#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 100;
const ll MOD = 1e9+7;
int N, L, A[MAXN+10];
ll dp[110][110][5000][4];
ll solve(int pos, int comp, int val, int state)
{
if(pos==N+1)
{
if(comp==1 && 0<=val && val<=L && state==3) return 1;
else return 0;
}
ll &ret=dp[pos][comp][val+2000][state];
if(ret!=-1) return ret;
ret=0;
int sz=__builtin_popcount(state);
ret+=(comp+1-sz)*solve(pos+1, comp+1, val-2*A[pos], state);
ret+=(comp*2-sz)*solve(pos+1, comp, val, state);
if(comp) ret+=(comp-1)*solve(pos+1, comp-1, val+2*A[pos], state);
if((state&1)==0) ret+=solve(pos+1, comp, val+A[pos], state|1);
if((state&1)==0) ret+=solve(pos+1, comp+1, val-A[pos], state|1);
if((state&2)==0) ret+=solve(pos+1, comp, val+A[pos], state|2);
if((state&2)==0) ret+=solve(pos+1, comp+1, val-A[pos], state|2);
//printf("%d %d %d %d : %lld\n", pos, comp, val, state, ret);
ret%=MOD;
return ret;
}
int main()
{
scanf("%d%d", &N, &L);
if(N==1) return !printf("1");
for(int i=1; i<=N; i++) scanf("%d", &A[i]);
sort(A+1, A+N+1);
memset(dp, -1, sizeof(dp));
printf("%lld\n", solve(1, 0, 0, 0));
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
42 | scanf("%d%d", &N, &L);
| ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:44:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | for(int i=1; i<=N; i++) scanf("%d", &A[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Runtime error |
295 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
289 ms |
524288 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Runtime error |
295 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |