【HDU2089】不要62【数位DP】【记忆化搜索】
来源:互联网 发布:软件开发是什么工作 编辑:程序博客网 时间:2024/05/16 07:53
【题目链接】
忘记写了个判断条件
如果上一位为6,当前为也为6,那么状态还是1。
/* Telekinetic Forest Guard */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 20;int dig[maxn];LL dp[maxn][3];// 0 ÎÞ 62// 1 ÓÐ 6// 2 ÓÐ 62 template <class numtype>inline void read(numtype &x) {int f = 0; x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? 1 : 0;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';if(f) x = -x;}inline LL dfs(int pos, int state, bool limit) {if(pos == 0) return state != 2;if(!limit && ~dp[pos][state]) return dp[pos][state];int upb = limit ? dig[pos] : 9;LL res = 0;for(int i = 0; i <= upb; i++) if(i ^ 4) {int s = state;if(state == 1) {if(i == 2) s = 2;else if(i != 6) s = 0;}else if(state == 0 && i == 6) s = 1;res += dfs(pos - 1, s, limit && i == dig[pos]);}if(!limit) dp[pos][state] = res;return res;}inline LL calc(LL x) {int top = 0;for(; x; x /= 10) dig[++top] = x % 10;return dfs(top, 0, 1);}int main() {LL l, r;memset(dp, -1, sizeof(dp));while(1) {read(l); read(r);if(!l && !r) break;printf("%lld\n", calc(r) - calc(l - 1));}return 0;}
0 0
- 【HDU2089】不要62【数位DP】【记忆化搜索】
- 【数位DP】 hdu2089 不要62
- 【数位DP】不要62 HDU2089
- HDU2089:不要62(数位DP)
- hdu2089 不要62 数位dp
- hdu2089 不要62 (数位DP)
- HDU2089 不要62 数位DP
- Hdu2089 - 不要62 - 数位dp
- hdu2089 不要62 数位dp
- 【数位DP】【HDU2089】不要62
- [HDU2089] 不要62 && 数位DP
- hdu2089 不要62 数位dp
- HDU2089 不要62 (数位DP)
- HDU2089 不要62 数位DP
- HDU2089 不要62【数位DP】
- hdu2089不要62【数位dp】
- hdu2089 不要62 数位DP
- hdu2089 不要62(数位DP)
- android 5.x—Palette图片取色调
- 4.图像标记<img>
- hdu 5675 ztr loves math【思维】
- 剑指offer(61):对称的二叉树
- TeamTalk---服务端架构
- 【HDU2089】不要62【数位DP】【记忆化搜索】
- 工厂方法模式
- android UI(1)-PopupWindow
- 74、JDK安装与环境变量配置
- leetcode-110. Balanced Binary Tree
- C语言
- 已更改或删除的行值要么不能使该行成为唯一行,要么改变了多个行
- HDU-4599 Dice (概率DP)
- UVA227 puzzle