您的位置:首页 > 其它

hdu_3555_Bomb(数位DP)

2016-05-29 16:16 411 查看

题目连接:hdu_3555_Bomb

题意:和2089一样,只是数据大了点,不过道理是一样的

 

#include<cstdio>
#include<cstring>
#define F(i,a,b) for(__int64 i=a;i<=b;i++)

__int64 t,n,dp[65][10][2],dig[65],len;

__int64 dfs(int pos,int pre,bool have,bool inf){
if(!pos)return have;
if(!inf&&dp[pos][pre][have]!=-1)return dp[pos][pre][have];
long long end=inf?dig[pos]:9,ans=0;
F(i,0,end)if(pre==4&&i==9)ans+=dfs(pos-1,i,1,inf&&(i==end));
else ans+=dfs(pos-1,i,have,inf&&(i==end));
if(!inf)dp[pos][pre][have]=ans;
return ans;
}

int main(){
memset(dp,-1,sizeof(dp));
scanf("%I64d",&t);
while(t--){
scanf("%I64d",&n);
for(len=0;n;n/=10)dig[++len]=n%10;
printf("%I64d\n",dfs((int)len,0,0,1));
}
return 0;
}
View Code

 




 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: