結果

問題 No.824 Many Shifts Hard
ユーザー chocoruskchocorusk
提出日時 2020-04-19 04:33:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 731 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 124,608 KB
最終ジャッジ日時 2025-01-09 21:23:12
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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 dp[2][303][303][303];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=1; i<=min(k, n-1); i++){
        dp[0][0][i][i+1]=1;
    }
    dp[1][0][k][k+1]=1;
    for(int i=0; i<k; i++){
        for(int j=0; j<=k; j++){
            for(int l=j+1; l<=k+1; l++){
                for(int t=0; t<2; t++){
                    int c=1;
                    if(j) (dp[t][i+1][j-1][l]+=dp[t][i][j][l])%=MOD, c++;
                    if(j+1<l) (dp[t][i+1][j][l-1]+=dp[t][i][j][l])%=MOD;
                    (dp[t][i+1][j][l]+=(n-c)*dp[t][i][j][l])%=MOD;
                }
            }
        }
    }
    ll ans=1;
    for(int i=0; i<k; i++) (ans*=(n-1))%=MOD;
    for(int i=0; i<=k; i++){
        for(int j=i+1; j<=k+1; j++){
            (ans+=dp[0][k][i][j]*j)%=MOD;
        }
    }
    if(n>=k+2){
        for(int i=0; i<=k; i++){
            for(int j=i+1; j<=k+1; j++){
                ll c=(n-k-1)*j+(ll)(n-k-1)*(n-k)/2;
                c%=MOD;
                (ans+=dp[1][k][i][j]*c)%=MOD;
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}
0