結果

問題 No.824 Many Shifts Hard
ユーザー chocoruskchocorusk
提出日時 2020-04-18 04:41:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,753 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 128,148 KB
実行使用メモリ 132,572 KB
最終ジャッジ日時 2024-04-14 20:04:16
合計ジャッジ時間 7,634 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,756 KB
testcase_01 AC 3 ms
7,752 KB
testcase_02 AC 131 ms
61,340 KB
testcase_03 AC 1,659 ms
109,212 KB
testcase_04 AC 786 ms
86,144 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll comb[303][303];
ll dp[303][303][303];
//ll dp2[302][302][302];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=0; i<=k; i++){
        comb[i][0]=1, comb[i][i]=1;
        for(int j=1; j<i; j++) comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%MOD;
    }
    for(int i=2; i<=k+1; i++){
        dp[i][1][1]=i-1;
        dp[i][1][2]=1;
        for(int l=2; l<=i; l++){
            for(int j=2; j<=k; j++){
                for(int m=1; m<j; m++){
                    (dp[i][j][l]+=dp[i-1][m][l-1]*comb[j-1][m])%=MOD;
                }
                if(l==2) dp[i][j][l]++;
            }
        }
        for(int j=2; j<=k; j++){
            for(int l=1; l<=i; l++){
                if(l==1){
                    (dp[i][j][l]+=dp[i][j-1][l]*(i-1)+dp[i][j-1][l+1])%=MOD;
                }else{
                    (dp[i][j][l]+=dp[i][j-1][l]*(i-2)+dp[i][j-1][l+1])%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        int m=min(n-i+1, k+1);
        ll p=1;
        for(int j=0; j<=k; j++){
            (ans+=comb[k][j]*p%MOD*i%MOD*((j==k)?1:dp[m][k-j][1]))%=MOD;
            (p*=(n-m))%=MOD;
        }
    }
    cout<<ans<<endl;
	return 0;
}
0