QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745470 | #7990. 广播 | ucup-team4352# | TL | 0ms | 0kb | C++23 | 1.0kb | 2024-11-14 10:10:56 | 2024-11-14 10:10:57 |
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000+5;
const int mod=1e9+7;
int T,k,m,n;
char s[maxn];
inline bool solve(int x) {
int js=1;
while(js<k&&js<4) {
js++;
int res=0;
while(x) {
res+=x%10;
x/=10;
}
x=res;
}
return x==m;
}
inline void add(int &x,int y) {
x+=y;
if(x>=mod) x-=mod;
}
int dp[maxn][2][9005];
bool vis[maxn][2][9005];
int dfs(int p,int flag,int sum) {
if(vis[p][flag][sum]) return dp[p][flag][sum];
if(p==n) {
if(sum==0) return 1;
return 0;
}
vis[p][flag][sum]=1;
int Max=9;
if(flag) Max=(s[p+1]-'0');
Max=min(Max,sum);
int res=0;
for(int i=0;i<=Max;++i) {
add(res,dfs(p+1,flag&&(i==Max),sum-i));
}
return dp[p][flag][sum]=res;
}
int main() {
T=5;
//scanf("%d",&T);
while(T--) {
n=1000;
for(int i=1;i<=1000;++i) s[i]='9';
m=1,k=6;
//scanf("%s%d%d",s+1,&k,&m),n=strlen(s+1);
int ans=0;
for(int j=0;j<=n*9;++j) if(solve(j)) add(ans,dfs(0,1,j));
printf("%d\n",ans);
memset(vis,0,sizeof(vis));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
4 2 2 1 3 2 4 2