QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745470#7990. 广播ucup-team4352#TL 0ms0kbC++231.0kb2024-11-14 10:10:562024-11-14 10:10:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 10:10:57]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-14 10:10:56]
  • 提交

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

output:


result: