結果

問題 No.41 貯金箱の溜息(EASY)
ユーザー krotonkroton
提出日時 2014-10-17 00:30:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 970 bytes
コンパイル時間 1,068 ms
コンパイル使用メモリ 71,756 KB
実行使用メモリ 20,900 KB
最終ジャッジ日時 2023-08-28 21:17:40
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
20,896 KB
testcase_01 AC 42 ms
20,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000009ll;

bool done[100000][20];
ll dp[100000][20];

int coin[] = {1, 1, 2, 3, 4, 5, 6, 7, 8, 9};

ll solve(ll k, int last){
    if(k == 0)return 1;
    if(last >= 10)return 0;
    
    if(done[k][last])return dp[k][last];
    
    ll res = 0;
    if(k >= coin[last]){
        res = solve(k - coin[last], last);
        res = (res + solve(k, last + 1)) % MOD;
    }
    
    
    done[k][last] = true;
    return dp[k][last] = res;
}

int main(){
    for(int k=0;k<100000;k++)for(int i=0;i<10;i++)solve(k, i);
    
    int T;
    cin >> T;
    
    while(T--){
        ll M;
        cin >> M;
        
        cout << solve(M / 111111, 0) << endl;
    }
    
    return 0;
}
0