hdu_3555_Bomb(数位DP)
2016-05-29 16:16
387 查看
题目连接:hdu_3555_Bomb
题意:和2089一样,只是数据大了点,不过道理是一样的
2089题解:http://blog.csdn.net/bin_gege/article/details/51531825
题解:见上
#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;
}
题意:和2089一样,只是数据大了点,不过道理是一样的
2089题解:http://blog.csdn.net/bin_gege/article/details/51531825
题解:见上
#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;
}
相关文章推荐
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android dpi,dip,dp的概念以及屏幕适配
- Android px、dp、sp之间相互转换
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- POJ-1695-Magazine Delivery-dp
- nyoj-1216-整理图书-dp
- TYVJ1193 括号序列解题报告
- 对DP的一点感想
- TYVJ上一些DP的解题报告
- soj1005. Roll Playing Games
- 01背包问题