結果
| 問題 |
No.269 見栄っ張りの募金活動
|
| コンテスト | |
| ユーザー |
Goi_dude
|
| 提出日時 | 2020-03-07 14:42:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 1,215 bytes |
| コンパイル時間 | 1,087 ms |
| コンパイル使用メモリ | 157,556 KB |
| 実行使用メモリ | 19,840 KB |
| 最終ジャッジ日時 | 2024-10-14 14:18:50 |
| 合計ジャッジ時間 | 1,905 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
int ans;
int n,s,k;
int a[101][20001],memo[101][20001]; // a[i][j] := i人でちょうどj円支払う方法
int f(int n,int s){
// k = 0 のときn人でちょうどs円払う方法
if(memo[n][s]++)return a[n][s];
// 0人で払えるのは0のみ s = 0 のとき 1 を返す
if(n==0)return s==0;
return a[n][s] = (f(n-1,s) + (s<n?0:f(n,s-n)))%mod;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> s >> k;
s -= k*((n-1)*n)/2;
if(s<0){
cout << 0 << endl;
return 0;
}else{
//cout << s << endl;
cout << f(n,s) << endl;
}
}
Goi_dude