結果

問題 No.269 見栄っ張りの募金活動
ユーザー HIcoder
提出日時 2023-10-10 23:39:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 935 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 101,568 KB
最終ジャッジ日時 2025-02-17 06:42:29
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<numeric>
#include<queue>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
const ll MOD=1e9+7;

int main(){
    ll N,S,K;
    cin>>N>>S>>K;

    S=S-K*N*(N-1)/2;
    if(S<0){
        cout<<0<<endl;
        return 0;
    }
    vector<vector<ll>> dp(S+1,vector<ll>(N+1,0));
    dp[0][0]=1;//0個のものを0人で分け与える
  

    for(int i=0;i<=S;i++){
        for(int j=1;j<=N;j++){
            if(i-j>=0){
                //i-j個の者をj個で分割
                dp[i][j]+=dp[i-j][j];
                dp[i][j]%=MOD;
            }
            //i個の者をj-1個で分割
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=MOD;
        }
    }

    cout<<dp[S][N]<<endl;

}
0