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
相关文章推荐
- 继承中的构造和析构函数
- 浅谈arduino与android通信
- ubuntu14.04Lts安装Tensorflow(2)
- NS2-HA
- Java基础
- iOS计步器功能实现之CoreMotion如何读取数据(二)
- The dialect was not set. Set the property hibernate.dialect
- 发表测试
- poj 2796 单调栈
- c++ 虚析构函数的作用分析
- 猎头们怎么看开源
- tcp/IP点对点通信程序
- 学习进度(2016.5.29)
- ASP.NET网站部署过程
- PTA第二次作业
- android开发_短信smsManager的导包问题
- 参数模型和非参数模型的区别
- 【DAY7】第七天的关于异常的练习
- Eclipse Debug不为人知的秘密
- 【设计模式】创建型模式之工厂方法Factory Method