POJ 2229 Sumsets(找规律,预处理)
参考了别人找的规律再理解
/*
8=1+1+1+1+1+1+1+1+1 1
8=1+1+1+1+1+1+1+2 2 3
8=1+1+1+1+2+2
8=1+1+1+1+4 4 5
8=1+1+2+2+2
8=1+1+2+4 6 7
8=2+2+2+2
8=2+2+4
8=4+4
8=8 8~9
*/
/*
以下引用自博客:http://blog.csdn.net/scorpiocj/article/details/5940456
如果i为奇数,肯定有一个1,把f[i-1]的每一种情况加一个1就得到fi,所以f[i]=f[i-1]
如果i为偶数,如果有1,至少有两个,则f[i-2]的每一种情况加两个1,就得到i,如果没有1,则把分解式中的每一项除2,则得到f[i/2]
所以f[i]=f[i-2]+f[i/2]
由于只要输出最后9个数位,别忘记模1000000000
*/ #include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; int a[]; int main()
{
a[]=;a[]=;
for(int i=;i<;i++)
{
if(i%)a[i]=a[i-];
else a[i]=(a[i-]+a[i/])%;
}
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",a[n]);
}
return ;
}
POJ 2229 Sumsets(找规律,预处理)的更多相关文章
- POJ 2229 Sumsets(规律)
这是一道意想不到的规律题............或许是我比较菜,找不到把. Description Farmer John commanded his cows to search for diffe ...
- poj 2229 Sumsets(dp)
Sumsets Time Limit : 4000/2000ms (Java/Other) Memory Limit : 400000/200000K (Java/Other) Total Sub ...
- POJ 2229 Sumsets(递推,找规律)
构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...
- 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 ...
- 暑假集训单切赛第一场 POJ 2309 BST(找规律的题)
题意:给出一棵二分搜索树,再给一个节点编号n,求以这个节点为根节点的子树叶子节点的最大值与最小值. 首先求n所在的层数,他的层数就是他的因子中2的个数(规律). n的左右各有num=2^i-1个数.最 ...
- POJ 1850 Code(找规律)
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7913 Accepted: 3709 Description ...
- Aggregated Counting(找规律 + 预处理)
Aggregated Counting 转 : https://blog.csdn.net/cq_phqg/article/details/48417111 题解: 可以令n=1+2+2+3+3+.. ...
- poj 2229 Sumsets 完全背包求方案总数
Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...
随机推荐
- Java开发中的几种对象的说明(PO,VO,DTO,BO,POJO,DAO,SAO等)
一.PO :(persistant object ),持久对象 可以看成是与数据库中的表相映射的java对象.使用Hibernate来生成PO是不错的选择. 二.VO :(value object) ...
- javaweb项目中获取项目名称
request.getServletContext().getContextPath() 增加项目名称是test.那么上面的结果就是/test
- WCF学习笔记——配置服务引用
WCF传过来的东西要序列化. 比如,在WCF服务中,象这么个方法 public IEnumerable<UserItem> GetUserList() 默认情况下,在客户端会调用,是这样: ...
- luogu3382【模板】三分法
给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 看代码即可. #include <cstdio> #include < ...
- hdu1150——最小点覆盖
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- bzoj3673 & bzoj3674 & 洛谷P3402 可持久化并查集
题目:bzoj3673:https://www.lydsy.com/JudgeOnline/problem.php?id=3673 bzoj3674:https://www.lydsy.com/Jud ...
- E20170821-mk
Dimension n. 尺寸; [复] 面积,范围; [物] 量纲; [数] 次元,度,维;
- 机器人走迷宫(dfs)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590 #include <stdio.h ...
- B - Magnets
Problem description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't ...
- Windows7环境下Composer 安装包的Cache目录位置
http://segmentfault.com/a/1190000000355928 https://getcomposer.org/doc/ 要说Composer的用法,以后再说,现在只记录wind ...