# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98469 | luciocf | Zoltan (COCI16_zoltan) | C++14 | 793 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 22;
const int mod = 1e9+7;
typedef long long ll;
int num[maxn], dp[maxn];
ll qtd[maxn];
int main(void)
{
int n;
ll q = 0LL;
cin >> n;
for (int i = 0; i < n; i++)
cin >> num[i];
int ans = 0;
for (int mask = 0; mask < (1<<n); mask++)
{
int aux = 0;
deque<int> dq;
if (!(mask&1)) continue;
for (int i = 0; i < n; i++)
{
if (mask&(1<<i)) dq.push_front(num[i]);
else dq.push_back(num[i]);
}
vector<int> v;
while (dq.size() > 0)
{
v.push_back(dq.front());
dq.pop_front();
}
for (int i = 0; i < v.size(); i++)
{
dp[i] = qtd[i] = 1;
for (int j = 0; j < i; j++)
if (v[j] < v[i])
dp[i] = max(dp[i], dp[j]+1);
}
for (int i = 0; i < v.size(); i++) aux = max(aux, dp[i]);
if (aux < ans) continue;
if (aux > ans) q = 0LL;
ans = aux;
for (int i = 0; i < v.size(); i++)
{
if (dp[i] < ans) continue;
q = (q+qtd[i])%mod;
for (int j = 0; j < i; j++)
if (v[j] < v[i] && dp[j]+1 == dp[i])
qtd[i] = (qtd[i]+qtd[j])%mod, q = (q+qtd[j])%mod;
}
}
cout << ans << " " << q << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |