hdoj 3555 Bomb
来源:互联网 发布:萤火虫之墓影评知乎 编辑:程序博客网 时间:2024/06/05 22:44
题目链接:Bomb
题目大意:给你一个N,问小于等于这个N的数里面“要49”的数有多少个
题目思路:跟不要62类似,数位dp去做就好了
#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;ll a[1005],dp[1005][2],n;ll dfs(ll pos,ll pre,ll sta,bool limit){ if(pos == -1) return 1; if(!limit&&dp[pos][sta] != -1) return dp[pos][sta]; ll up = limit?a[pos]:9; ll tmp = 0; for(ll i = 0;i <= up;i++){ if(pre == 4&&i == 9) continue; tmp += dfs(pos-1,i,i == 4,limit&&i == a[pos]); } if(!limit) dp[pos][sta] = tmp; return tmp;}ll solve(ll x){ ll pos = 0; while(x){ a[pos++] = x%10; x/=10; } return dfs(pos-1,-1,0,true);}int main(){ ll t,n; memset(dp,-1,sizeof(dp)); scanf("%lld",&t); while(t--){ scanf("%lld",&n); printf("%lld\n",n-solve(n)+solve(0)); } return 0;}
阅读全文
0 0
- 【DP】 HDOJ 3555 Bomb
- HDOJ 3555 Bomb
- HDOJ 3555 Bomb
- 【HDOJ 3555】Bomb
- HDOJ 3555 Bomb
- HDOJ 3555 Bomb
- hdoj-【3555 Bomb】
- hdoj 3555 Bomb
- hdoj 3555 BOMB(数位dp)
- HDOJ 3555 Bomb 【数位dp】
- hdoj 3555 Bomb 【数位dp】
- HDOJ 题目3555 Bomb(数位dp)
- HDOJ 题目3555 Bomb(数位dp)
- HDOJ 题目3555 Bomb(数位DP)
- hdoj 3622 Bomb Game
- HDOJ 3622 Bomb Game
- hdoj 5934 Bomb
- hdoj 3555 Bomb/ hdoj 3652 B-number 数位DP 初解禁!!
- JAVA向上转型,构造函数
- laravel5搭建过程问题
- 数据库连接池
- ajax的json和jsonp以及web的应用
- 详解Java中的正则表达式
- hdoj 3555 Bomb
- [数位DP+矩阵快速幂优化]BZOJ 1875——[SDOI2009]HH去散步
- error LNK2005: "public: __cdecl std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofst
- Android View的事件分发机制和滑动冲突解决
- ubuntu配置静态ip
- caffe 修改源码多标签输入
- 腾讯云系列二:Centos7 安装 Tomcat服务器
- Error:(xx) Error: "xxxxxxx" is not translated in "en" (English)[MissingTranslation]
- 计算几何(point&line)红书模板