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;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fori(x,a,b) for(int x=a;x<=b;x++)
#define ford(x,a,b) for(int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);
const int mod = 1e9+7;
int f[105][105][1005][3];
int n,l,a[105];
void add(int &a,int b)
{
a+=b;
if(a>=mod) a-=mod;
}
main()
{
//freopen("task.inp","r",stdin);
fasty;
cin>>n>>l;
fori(i,1,n) cin>>a[i];
sort(a+1,a+n+1);
if(n==1) return cout<<1,0;
f[0][0][0][0] = 1;
//ed : so luong end point da dc fill
a[n+1] = 100000;
fori(i,1,n) fori(j,1,i) fori(k,0,l) fori(ed,0,2)
{
int diff = (2*j-ed)*(a[i+1]-a[i]);//neu a[i] ko phai ed(end point)=> xuat hien 2 lan hoac ko xuat hien
if(k<diff || i+j+1-ed>n) continue;
add(f[i][j][k][ed],f[i-1][j-1][k-diff][ed]);//a[i] ko la endpoint
if(ed>=1) add(f[i][j][k][ed],(3-ed)*f[i-1][j-1][k-diff][ed-1]%mod);//a[i] la 1 endpoint;
add(f[i][j][k][ed],(2*j-ed)*f[i-1][j][k-diff][ed]%mod);//a[i] nhet vao 1 cc ko chua endpoint;
if(ed==1) add(f[i][j][k][ed],2*j*f[i-1][j][k-diff][ed-1]%mod);//chon 1 dau lam endpoint dau tien
if(ed==2)
{
if(i==n) add(f[i][j][k][ed],f[i-1][j][k-diff][ed-1]);//1 cach duy nhat la a[n]
else if(j>1) add(f[i][j][k][ed],(j-1)*f[i-1][j][k-diff][ed-1]%mod);
}
if(ed==2)
{
if(i==n) add(f[i][j][k][ed],f[i-1][j+1][k-diff][ed]);//hop 2 cc con lai
else add(f[i][j][k][ed],j*(j-1)%mod*f[i-1][j+1][k-diff][ed]%mod);
}
else if(ed==1) add(f[i][j][k][ed],j*j%mod*f[i-1][j+1][k-diff][ed]%mod);
else add(f[i][j][k][ed],j*(j+1)%mod*f[i-1][j+1][k-diff][ed]%mod);
}
int kq = 0;
fori(k,0,l) add(kq,f[n][1][k][2]);
cout<<kq;
}
Compilation message (stderr)
skyscraper.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |