hdu4734(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734
思路:记忆化搜索。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int Pow[];
int dp[][];
int digit[];
int a,b; int Get_f(int n)
{
int pos=,res=;
while(n){
digit[pos++]=n%;
n/=;
}
for(int i=;i<pos;i++)res+=digit[i]*Pow[i];
// cout<<res<<"**"<<endl;
return res;
} int dfs(int pos,int res,int doing)
{
if(res<)return ;
if(pos==-)return ;
if(!doing&&dp[pos][res]!=-)return dp[pos][res];
int End=doing?digit[pos]:;
int ans=;
for(int i=;i<=End;i++){
ans+=dfs(pos-,res-i*Pow[pos],doing&&i==End);
}
if(!doing){
dp[pos][res]=ans;
}
return ans;
} int Solve(int res,int n)
{
int pos=;
while(n){
digit[pos++]=n%;
n/=;
}
return dfs(pos-,res,);
} int main()
{
memset(dp,-,sizeof(dp));
Pow[]=;
for(int i=;i<=;i++)Pow[i]=Pow[i-]<<;
int _case,t=;
scanf("%d",&_case);
while(_case--){
scanf("%d%d",&a,&b);
printf("Case #%d: ",t++);
printf("%d\n",Solve(Get_f(a),b));
}
return ;
}
hdu4734(记忆化搜索)的更多相关文章
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
- 【BZOJ-3895】取石子 记忆化搜索 + 博弈
3895: 取石子 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 263 Solved: 127[Submit][Status][Discuss] D ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- zoj 3644(dp + 记忆化搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...
- loj 1044(dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...
- DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...
- HDU1978 记忆化搜索
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- bzoj4562: [Haoi2016]食物链--记忆化搜索
这道题其实比较水,半个小时AC= =对于我这样的渣渣来说真是极大的鼓舞 题目大意:给出一个有向图,求入度为0的点到出度为0的点一共有多少条路 从入读为零的点进行记忆化搜索,搜到出度为零的点返回1 所有 ...
- 数位dp/记忆化搜索
一.引例 #1033 : 交错和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an ...
随机推荐
- mysql 禁制远程连接
改表法:把host地址改为% use mysql; update user set host = '%' where user = 'root'and host="127.0.0.1&quo ...
- 把一个一中的字段更新另一个表中的t-sql
UPDATE dbo.CommDescr SET Descr=(SELECT ba.content FROM dbo.blog_article ba WHERE ba.id=3) WHERE Comm ...
- postgresql一般crud存储过程参考[转]
http://blog.csdn.net/cdnight/article/details/18082255 这里是一份经过再三调试测试而成功的postgres数据库单表crud存储过程,请注意,对于多 ...
- 使用spring AOP获得session的思路
由于Spring 的AOP面向切面编程,与Servlet容器没有任何关联,所以想要获得Session会话比较麻烦. 当然Struts2同样不依赖Servlet容器,可以在Spring AOP中可以使用 ...
- Win32 SDK - 打开文件对话框
OPENFILENAME ofn; // common dialog box structure TCHAR szFile[MAX_PATH]; // buffer for file name // ...
- Hive 指定分隔符,将表导出到本地
hive表的数据源有四种: hbase hdfs 本地 其他hive表 而hive表本身有两种: 内部表和外部表. 而hbase的数据在hive中,可以建立对应的外部表(参看hive和hbase整合) ...
- mac shell终端编辑命令行快捷键——行首行尾
mac shell终端编辑命令行快捷键——行首行尾 ctrl+a //移到行首ctrl+e //移到行尾===========linux系统用============alt+a //移到光标所在单词首 ...
- 没有msdtc服务的解决方法(sql server分布式事务挂掉的解决方法)
没有msdtc服务的解决方法如下:1.删除注册表中的键: 开始 运行 regedit 打开注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic ...
- unity5,UI Button too small on device than in Game View解决办法
假设测试设备为iphone5(横屏).下面说明如何使真机上ui显示效果与Game View中一致. 1,首先Game View左上角屏幕规格选 iPhone 5 Wide (16:9),如图: 2,在 ...
- [na]office 2010 2013卸载工具
http://www.ithome.com/html/soft/32777.htm Office 2003 || Office 2007 || Office 2010.