【HDU 4734】 F(x)
来源:互联网 发布:linux mount cifs 编辑:程序博客网 时间:2024/05/22 06:49
Problem
http://acm.hdu.edu.cn/showproblem.php?pid=4734
Solution
还是记忆化数位DP,到现在我发现记忆化的写法就是一个大暴力的优化,记录的就是到现在接下来继续搜会有的结果,解释这样,所以在某些题目上只能多花点空间,而且数组的含义也有点区别。
CODE
/* * @key word:digit DP * @tesed on:HDU4734 31ms * @Author: lhq * @Date: 2017-08-17 18:50:39 * @Last Modified by: lhq * @Last Modified time: 2017-08-17 18:51:01 */#include <iostream>#include <cstdio>#include <cstring>using namespace std;int dp[12][10000], a[12], n, m;int dfs(int len, int sum, bool limit){ if (len == 0) return sum >= 0 ? 1 : 0; if (sum < 0) return 0; if (!limit && dp[len][sum] != -1) return dp[len][sum]; int up = limit ? a[len] : 9; int ans = 0; for (int i = 0; i <= up; i++) ans += dfs(len - 1, sum - i * (1 << len - 1), limit && i == up); if (!limit) dp[len][sum] = ans; return ans;}int solve(int x){ int len = 0, y = 0, fx = 0; while (x) { a[++len] = x % 10; x /= 10; } while (n) { fx += (n % 10) * (1 << y); y++, n /= 10; } return dfs(len, fx, true);}int main(){ int T; cin >> T; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= T; i++) { scanf("%lld%lld", &n, &m); printf("Case #%d: %d\n", i, solve(m)); } return 0;}
阅读全文
0 0
- hdu 4734 F(x)
- HDU 4734 F(x)
- hdu 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- hdu 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- hdu 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- HDU 4734 F(x)
- 【HDU 4734】 F(x)
- HDU 4734F(x)
- HDU 4734 f(x)
- hdu 4734 F(x)(DP)
- Linux中` `、$、$( ) 、${ } 有什么区别
- 1 ,js入门基础
- sqlserver数据库大型应用解决方案总结 数据库负载均衡
- HDU 6134 莫比乌斯反演
- ORM简介
- 【HDU 4734】 F(x)
- poj 1659 Frogs' Neighborhood havel定理
- KMP
- HDU 6134 && 2017 多校训练:Battlestation Operational(莫比乌斯反演+积性函数)
- java中类的方法初始化顺序
- freeswitch系列二 kamailio 5.0安装及实现kamailio集成freeswitch
- fastjson浮点类型显示科学计数法的问题
- springmvc常用注解标签详解
- 【项目实战】自监控-12-自动发送邮件