您的位置:首页 > 其它

[数位DP]Hdu 3555——Bomb

2017-10-06 21:28 465 查看

题目梗概

求不超过n的含49的数字的个数。

解题思路

数位DPSB题。

#include<cstdio>
#define LL long long
using namespace std;
LL n,f[25][15],x;
int a[25],len,t;
LL DFS(int len,int lst,int pd){
if (len<1) return 1;
if (!pd&&f[len][lst]!=0) return f[len][lst];
int now;if (!pd) now=9;else now=a[len];
LL num=0;
for (int i=0;i<=now;i++)
if (lst!=4||i!=9) num+=DFS(len-1,i,pd&&(i==now));
if (!pd) f[len][lst]=num;
return num;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
len=0;x=n;
while(x>0){
a[++len]=x%10;
x/=10;
}
printf("%lld\n",n+1-DFS(len,0,1));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: