QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377483 | #7996. 报数 IV | plutos | TL | 8ms | 38904kb | C++17 | 1.5kb | 2024-04-05 14:10:45 | 2024-04-05 14:10:47 |
Judging History
answer
#include <bits/stdc++.h>
void Yes() {
std::cout << "YES" << "\n";
return;
}
void No() {
std::cout << "NO" << "\n";
return;
}
template<typename T>
void out(T x) { std::cout << x << "\n"; }
using namespace std;
//using int = long long;
using PII = pair<int, int>;
const int N = 2e5 + 10;
int k, m;
string n;
int a[1005];
int dp[1004][9004];
const int mod = 1e9 + 7;
//int tong[9001];
int cc(int x) {
int tmp = 0;
while (x) {
tmp += x % 10;
x /= 10;
}
return tmp;
}
int dfs(int pos, int sum, int lim, int lead0) {
if (pos == 0)
{
for (int i = 1; i <= k - 1; i++) {
sum = cc(sum);
}
return sum == m;
}
if (!lim && !lead0 && dp[pos][sum] != -1) {
return dp[pos][sum];
}
int up = lim ? a[pos] : 9;
int tmp = 0;
for (int i = 0; i <= up; i++) {
tmp += dfs(pos - 1, sum + i, lim && (i == up), lead0 && (i == 0));
tmp%=mod;
}
if (!lim && !lead0) {
return dp[pos][sum] = tmp;
}
return tmp;
}
int cal(string s) {
int len = 0;
reverse(s.begin(), s.end());
for (auto p: s) {
a[++len] = p - '0';
}
return dfs(len, 0, 1, 1);
}
void Solve() {
for (int i = 0; i <= 1002; i++)
for (int j = 0; j <= 9001; j++)
dp[i][j] = -1;
cin >> n >> k >> m;
k = min(k, 5);
cout << cal(n) <<"\n";
}
signed main() {
int t = 1;
cin>>t;
while (t--)
Solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 38864kb
input:
2 114 1 5 514 2 10
output:
8 10
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 8ms
memory: 38904kb
input:
5 114 1 5 514 2 10 114514 3 7 1919810 2 13 1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79
output:
8 10 12724 504 481046284
result:
ok 5 lines
Test #3:
score: -100
Time Limit Exceeded
input:
5 3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...
output:
0 613343513 0 500149787 932367667