제출 #853976

#제출 시각아이디문제언어결과실행 시간메모리
853976NotLinuxMagneti (COCI21_magneti)C++17
110 / 110
326 ms204636 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e4 + 7; const int mod = 1e9 + 7; inline void add(int &x , int &y , int coef){ x = (x + y * coef % mod) % mod; } inline int fastpow(int a , int b){ if(b == 0)return 1; if(b == 1)return a; int val = fastpow(a,b/2); return val * val % mod * (b&1?a:1) % mod; } void solve(){ int fact[N],invfact[N]; fact[0] = invfact[0] = 1; for(int i = 1;i<N;i++){ fact[i] = fact[i-1] * i % mod; invfact[i] = fastpow(fact[i] , mod-2); } function < int (int , int) > Cr = [&](int n , int r){//n tane sepete , x tane top return fact[n] * invfact[r] % mod * invfact[n-r] % mod; }; int n,l; cin >> n >> l; int arr[n]; for(int i = 0;i<n;i++){ cin >> arr[i]; } sort(arr , arr + n); int dp[n+1][n+1][l+5]; memset(dp , 0 , sizeof(dp)); dp[0][0][0] = 1; for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ for(int k = 0;k<=l;k++){ /*if(dp[i][j][k]){ cout << i << " " << j << " " << k << " => " << dp[i][j][k] << endl; }*/ //create a new component add(dp[i+1][j+1][k + 1] , dp[i][j][k] , j+1); //add to the right and left if((k + arr[i]) <= l){ add(dp[i+1][j][k + arr[i]] , dp[i][j][k] , 2 * j % mod); } //merge two components if(j > 1 and (k + 2 * arr[i] - 1) <= l){ add(dp[i+1][j-1][k + 2 * arr[i] - 1] , dp[i][j][k] , j-1); } } } } int ans = 0; for(int i = 0;i<l;i++){//i = boşluk miktarı int locans = dp[n][1][l - i] * Cr(n + i, n) % mod; add(ans , locans , 1); } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int testcase = 1;//cin >> testcase; while(testcase--)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...