#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int mod=inf;
inline int add(int x,int y)
{
return x+y<mod?x+y:x+y-mod;
}
inline int mul(int x,int y)
{
return(int)((ll)x*y%mod);
}
int dp[20010][15][105];
vector<int>lst[15];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,l;
cin>>n>>l;
vector<int>v(n);
for(int&t:v)
cin>>t;
for(int i=0;i<1<<n;i++)
lst[__builtin_popcount(i)].eb(i);
for(int i=0;i<n;i++)
dp[1<<i][i][0]=1;
for(int le=1;le<n;le++)
{
for(int&t:lst[le])
{
for(int i=0;i<n;i++)
{
if((t>>i&1)==0)
continue;
for(int j=0;j<n;j++)
{
if((t>>j&1)==1)
continue;
int dif=abs(v[i]-v[j]);
int nx=t|(1<<j);
for(int len=dif;len<=l;len++)
dp[nx][j][len]=add(dp[nx][j][len],dp[t][i][len-dif]);
}
}
}
}
int ans=0;
for(int i=0;i<n;i++)
for(int len=0;len<=l;len++)
ans=add(ans,dp[(1<<n)-1][i][len]);
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1888 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
25464 KB |
Output is correct |
2 |
Correct |
211 ms |
101272 KB |
Output is correct |
3 |
Correct |
168 ms |
101240 KB |
Output is correct |
4 |
Correct |
212 ms |
101244 KB |
Output is correct |
5 |
Correct |
203 ms |
101240 KB |
Output is correct |
6 |
Correct |
228 ms |
101240 KB |
Output is correct |
7 |
Correct |
137 ms |
101240 KB |
Output is correct |
8 |
Correct |
165 ms |
101240 KB |
Output is correct |
9 |
Correct |
215 ms |
101240 KB |
Output is correct |
10 |
Correct |
195 ms |
101368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1888 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |