Ignatius and the Princess III(方案背包+搜索)
就是问你,n这个数可以被多少种方案组成。
比如:
算是,方案+完全背包的模板题了。
#include<iostream>
#include<cstring>
using namespace std;
int dp[];
int main()
{
int n;
while (~scanf("%d", &n)){
memset(dp, , sizeof(dp));
dp[] = ;
for (int i = ; i <= n;++i)
for (int j = i; j <=n; ++j)
dp[j] += dp[j - i];
printf("%d\n", dp[n]);
}
}
我试了试暴力搜索,不幸超时,搜在50以内还可以
#include<iostream>
#include<cstring>
using namespace std;
int num[],sum, ans;
void dfs(int cur, int n)
{
if (sum == n)ans++;
else
{
for (int i = ; i <= n; ++i)
{
if (i >= num[cur - ])
{
sum += i;
if (sum <= n)
{
num[cur] = i;
dfs(cur + , n);
sum -= i;
}
else{
sum -= i;
return;
}
}
}
}
} int main()
{
int n;
while (~scanf("%d", &n))
{
sum = , ans=;
memset(num, , sizeof(num));
dfs(, n);
printf("%d\n", ans);
}
}
Ignatius and the Princess III(方案背包+搜索)的更多相关文章
- HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- hdu 1028 Ignatius and the Princess III (n的划分)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- HDOJ 1028 Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU1028 Ignatius and the Princess III 【母函数模板题】
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Ignatius and the Princess III --undo
Ignatius and the Princess III Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (J ...
随机推荐
- C#生成ZIP压缩包
生成ZIP压缩包C#代码如下: using System; using System.Collections.Generic; using System.Text; using ICSharpCode ...
- MVC架构介绍-Model的开发
需要在派生类实现lEntity,IEntity的两个属性EntityId和IsDeleteInDataBase,以显式方式实现 Model的所有属性存入数据库以前都要确保有相应的默认值,不要依赖数据库 ...
- 【Java基础】1、java中的instanceof
instanceof是Java.php的一个二元操作符(运算符),和==,>,<是同一类东西.由于它是由字母组成的,所以也是Java的保留关键字.它的作用是判断其左边对象是否为其右边类的实 ...
- HDU6201
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- Django Rest framework 之 权限
django rest framework 之 认证(一) django rest framework 之 权限(二) django rest framework 之 节流(三) django res ...
- Bootstrap 、AngularJs
SPA 全称:single-page application单页面应用 说明:类似原生客户端软件更流畅的用户体验的页面.所有的资源都是按需加载到页面上. JSR 全称:Java Specificati ...
- JS的一些小知识
1. 0.1+0.2==0.3? 结果为false 原因:由于计算机是用二进制来存储和处理数据数字,不能精确表示浮点数,而JavaScript是一种弱类型语言,没有相应的封装类来处理浮点数运算 ...
- js动态控制表单表格
js动态控制表单表格,这里操作只讲,添加一行,删除一行,删除某一行某一列. 直接放代码: <!DOCTYPE html> <html> <head> <met ...
- JavaScript异步和单线程
一,同步和异步的区别: 同步会阻塞代码执行,而异步不会.(比如alert是同步,setTimeout是异步) 二,前端使用异步的场景: 1,定时任务:setTimeout,setInterval 2, ...
- JQuery请求数据的方式
/*$.ajax常用的几个参数 // 1.url:要求为String类型的参数,(默认为当前页地址)发送请求的地址. // 2.type:要求为String类型的参数,请求方式(post或get)默认 ...