【POJ】2229 Sumsets(递推)
| Time Limit: 2000MS | Memory Limit: 200000K | |
| Total Submissions: 20315 | Accepted: 7930 |
Description
1) 1+1+1+1+1+1+1
2) 1+1+1+1+1+2
3) 1+1+1+2+2
4) 1+1+1+4
5) 1+2+2+2
6) 1+2+4
Help FJ count all possible representations for a given integer N (1 <= N <= 1,000,000).
Input
Output
Sample Input
7
Sample Output
6
Source
#include <cstdio>
#include <algorithm>
using namespace std;
int w[],dp[];
int main()
{
int a=,n;
scanf("%d",&n);
for(int i=;i<=;i++)
{
w[i]=a;
a*=;
}
dp[]=;
for(int i=;i<=;i++)
for(int j=w[i];j<=;j++)
{
dp[j]+=dp[j-w[i]];
dp[j]%=;
}
printf("%d",dp[n]%);
return ;
}
【POJ】2229 Sumsets(递推)的更多相关文章
- POJ 2229 Sumsets(递推,找规律)
构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...
- poj2229 Sumsets (递推)
http://poj.org/problem?id=2229 看到题目能感觉到多半是动态规划,但是没有清晰的思路. 打表找规律: #include<cstdio> #include< ...
- poj 2506 Tiling 递推
题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...
- hdu2709 Sumsets 递推
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2709 感觉很经典的一道递推题 自己想了有半天的时间了....比较弱.... 思路: 设f[n]表示和为 ...
- POJ 2478 线性递推欧拉函数
题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- Strange Towers of Hanoi POJ - 1958(递推)
题意:就是让你求出4个塔的汉诺塔的最小移动步数,(1 <= n <= 12) 那么我们知道3个塔的汉诺塔问题的解为:d[n] = 2*d[n-1] + 1 ,可以解释为把n-1个圆盘移动到 ...
- poj 2229 Sumsets(dp)
Sumsets Time Limit : 4000/2000ms (Java/Other) Memory Limit : 400000/200000K (Java/Other) Total Sub ...
- poj 2229 Sumsets 完全背包求方案总数
Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...
随机推荐
- Linux基础三(正则表达式)
语法(部分) 字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符.例如,“n”匹配字符“n”.“\n”匹配一个换行符.序列“\\”匹配“\”而“\(”则匹配“(”. ^ 匹配输入字符串的开 ...
- [转载][QT][SQL]sql学习记录4_sqlite约束
转载自:定义以及示例请见 : http://www.runoob.com/sqlite/sqlite-constraints.html SQLite 约束 约束是在表的数据列上强制执行的规则.这些是用 ...
- .net core web 中使用app.UseRouter的几种使用方式
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ...
- hiredis处理zscan和hscan的reply
zscan的返回值可以看做是一个二维数组,第一维包含两个元素:string类型的游标cursor和集合元素数组:第二维即集合元素数组,这个数组交替存放着集合元素和score,元素和score也都是st ...
- 通过拖拽prefab来存储相应的路径
更新了一下,支持数组和嵌套数据结构. using UnityEngine; using System.Collections; using UnityEditor; using System.Refl ...
- CentOS 7.4中firewall防火墙详解和配置以及切换为iptables防火墙
转载:https://blog.csdn.net/xlgen157387/article/details/52672988 一.firewall介绍 CentOS 7中防火墙是一个非常的强大的功能,在 ...
- Loj 538 递推数列
Loj 538 递推数列 出题人:这题提高难度吧.于是放在了%你赛的 \(D1T2\) . 递推式为 \(a_i=k*a_{i-1}+a_{i-2}\) , 注意到 \(k\in \mathbb{N_ ...
- 如何删除 Windows 10 系统生成的 WindowsApps 文件夹
如果曾经修改过 Windows 10 应用安装路径到非系统盘,那么那个盘下就会生成一些文件夹.如果以后重装了系统或者应用删除了,挪位置了,那些文件夹依然在那里——删不掉! 大家都知道这是权限问题,然而 ...
- 《selenium2 python 自动化测试实战》(5)——键盘事件
键盘事件,就是键盘上的一些操作,比如Ctrl +C,Ctrl+V,Ctrl+X等. 对键盘的操作需要导入另一个键盘的库: from selenium.webdriver.common.keys imp ...
- LeetCode Word Abbreviation
原题链接在这里:https://leetcode.com/problems/word-abbreviation/description/ 题目: Given an array of n distinc ...