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 ...
随机推荐
- 我对alias的重新认识:通过alias让rm更安全
bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html rm的悲剧总是发生在不经意之间,所以无论是在shell脚本中还 ...
- 【操作系统】二、JVM线程与Linux内核线程的映射
Linux从内核2.6开始使用NPTL (Native POSIX Thread Library)支持,但这时线程本质上还轻量级进程. Java里的线程是由JVM来管理的,它如何对应到操作系统的线程是 ...
- 第一篇 Spring boot 配置文件笔记
spring boot 不需要配置太多文件程序便可正常运行,特殊情况需要我们自己配置文件. 项目以IDEA写实例,系统会默认在src/main/java/resources目录下创建applicati ...
- Raspberrypi 3B+ 安装 php+sqlite
按照网上的命令都为安装php5-fpm 和 php5-sqlite, 但是发现无法找到软件,可能是系统版本比较高的缘故,原来的版本已经不支持了. 经过努力华找到如下安装方法 sudo apt-get ...
- 【作业一】Android开发环境以及开发前的准备
对于Android平台的开发工具,我知道的就是Eclipse和Android Studio(后面简称AS).之前在学习JAVA时,渐渐习惯了Eclipse,后来要搭建Android的开发环境时,本来也 ...
- deepin使用笔记-解决安装并解决gvim没有启动器的问题
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 1.安装gvim #apt-get install vim-gtk3 2.创建桌面启动器 创建/usr/share/applic ...
- SQL Server: create table sql script
---摇奖observeh数据库设计 Function getSpace lottery /* -- Author:geovindu 涂聚文 -- Date: 20180427 为了自写生成代码.根据 ...
- csharp: using HtmlAgilityPack and ScrapySharp reading Url find text
https://github.com/exaphaser/ScrapySharp https://github.com/zzzprojects/html-agility-pack https://gi ...
- 【读书笔记】iOS-访问iPod媒体库
iOS设备内部都有一个iPod媒体库,在这个媒体库中包含了音频和视频文件,它的来源主要是苹果公司的iTunes Store,现在苹果公司的iTunes Store内容很多,但能够下载到iPod媒体库的 ...
- vue.js及项目实战[笔记]— 01 vue.js
一. vue基础 1. 历史介绍 angular 09年,年份较早,一开始大家是拒绝的 react 2013年,用户体验较好,直接拉到一堆粉丝 vue 2014年,用户体验较好 前端框架与库的区别 j ...