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 ...
随机推荐
- [Luogu4986] 逃离
Description 给定次数为 \(n\) 的函数 \(A(x),B(x),C(x)\),求 \(A^2(x)+B^2(x)-C^2(x)\) 在 \([L,R]\) 的零点.\(n\leq 10 ...
- css布局------左右宽度固定,中间宽度自适应容器
HTML /*适用方法1,方法2*/<body> <div class="container"> <div class="left" ...
- WPF 使用 Direct2D1 画图入门
本文来告诉大家如何在 WPF 使用 D2D 画图. 本文是一个系列 WPF 使用 Direct2D1 画图入门 WPF 使用 Direct2D1 画图 绘制基本图形 WPF 使用 SharpDX WP ...
- autocomplate 学习
方法一 :[使用插件] // 联想功能 stat function cselstreet() { var name = ""; //$("#txtname"). ...
- Java高级类特性(二)
一.static关键字 static关键字用来声明成员属于类,而不是属于类的对象.1). static (类)变量类变量可以被类的所有对象共享,以便与不共享的成员变量区分开来. static变量也称作 ...
- C# Why does '+' + a short convert to 44
I have a line of code that looks like this: MyObject.PhoneNumber = '+' + ThePhonePrefix + TheBizNumb ...
- csharp: read system DSN configured get Driver Names on windows
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C# 6 元组应用 Part 1:方便的字典工厂方法
首先是简单的实现: public static class CollectionExtensions { public static IDictionary<TKey, TValue> M ...
- Apex的对象共享
Apex的对象共享 在Apex中,每个对象都有一个"共享"对象,其中存储了该对象的共享设定. 这种共享对象以"share"结尾.比如Account的共享对象是A ...
- spring资源访问接口和资源加载接口
spring 资源访问接口 JDK提供的资源访问类,如java.net.URL.File等,不能很好地满足各种资源的访问需求,比如缺少从类路径或者Web容器的上下文中获取资源的操作类. 鉴于此,spr ...