这是一道意想不到的规律题。。。。。。。。。。。。或许是我比较菜,找不到把。

Description

Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7:

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

A single line with a single integer, N.

Output

The number of ways to represent N as the indicated sum. Due to the potential huge size of this number, print only last 9 digits (in base 10 representation).

Sample Input

7

Sample Output

6

规律是:1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 36,,,由这里不难可以看出,如果是奇数位,则于他前一位相当。。。重点是偶数位,d[i]=d[i-1]+d[i/2],这规律真的是。。。。
AC代码:
#define MOD 10000000000
#define MAX 20000
#include<stdio.h>
int d[MAX];
int main()
{
int n;
scanf("%d",&n);
d[]=;
d[]=;
for(int i= ;i<=n ;i++)
if(i & )
d[i]=d[i-]%MOD;
else
d[i]=(d[i-]+d[i/])%MOD;
printf("%d\n",d[n]);
return ;
}

POJ 2229 Sumsets(规律)的更多相关文章

  1. 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. POJ 2229 Sumsets(递推,找规律)

    构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...

  3. poj -2229 Sumsets (dp)

    http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...

  4. poj 2229 Sumsets(dp)

    Sumsets Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Sub ...

  5. POJ 2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Descrip ...

  6. poj 2229 Sumsets 完全背包求方案总数

    Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...

  7. poj 2229 Sumsets DP

    题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...

  8. poj 2229 Sumsets(dp 或 数学)

    Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...

  9. poj 2229 Sumsets(记录结果再利用的DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 将一个数N分解为2的幂之和共有几种分法? 题解: 定义dp[ i ]为数 i 的 ...

随机推荐

  1. python爬虫(10)--PyQuery的用法

    简介 pyquery 可让你用 jQuery 的语法来对 xml 进行操作.这I和 jQuery 十分类似.如果利用 lxml,pyquery 对 xml 和 html 的处理将更快. 初始化 在这里 ...

  2. Codeforces #499 Div2 E (1010C) Border

    一直第9个样例WA,发现事情没有这么简单的时候只剩20分钟了...... 看了一些大神提交的代码,发现还能这么玩..... 这个题目可以转化成这个问题:给一堆[0,m)之间的数,可以随意组合成新的数( ...

  3. 单选与复选控件JRadioButton与JCheckBox的使用

    -----------------siwuxie095 工程名:TestUI 包名:com.siwuxie095.ui 类名:TestTextFieldAndTextArea.java 工程结构目录如 ...

  4. 利用General框架进行三层架构开发

    三层架构是企业信息管理系统中一种比较流行的架构方式,如大家所知,三层架构将信息系统分为数据访问层(DAL).业务逻辑层(BLL).界面表示层(UI)三部分,三层架构的好处是根据系统中代码所处的层次将系 ...

  5. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-009Polymorphic collections(@OneToMany(mappedBy = "user")、@ManyToOne、)

    一.代码 1. package org.jpwh.model.inheritance.associations.onetomany; import org.jpwh.model.Constants; ...

  6. 20、Basic Shell_for_while_grep_find

    转载:https://github.com/swcarpentry/DEPRECATED-boot-camps/blob/master/shell/shell_cheatsheet.md 1.For ...

  7. bzoj4619 4619: [Wf2016]Swap Space

    传送门 分析 首先不难想到我们要先处理容量变大的再处理容量变小的 对于第一种情况我们自然要选择x小的先格式化,因为这个样暂时存储所需空间较小,可以使得情况更优 而第二种情况y先考虑,因为这样对总空间的 ...

  8. (转)Linux操作系统下VMware的多网卡桥接转换

    VMware,鼎鼎大名的虚拟机软件,没有人不知道吧?当然,在Linux下使用虚拟机软件,并不一定需要使用VMWare,Xen也是非常不错的选择,有很多评测就认为XEN的表现优于VMware.可惜的是X ...

  9. scala中的注解

    scala中很多注解实现java中关键字的用法 @volatile注解标记为易失的:@transient注解将字段标记为瞬态的:@strictfp注解对应strictfp修饰符:@native注解标记 ...

  10. 开启wifi后不能ping通本机 Cann't ping the local PC while start a wlan

    问题如题:今天发现一个问题,测试本机ip时候有时候总是获取失败,后来才发现是wifi共享软件导致的缘故. 本来呢?我买的是小米wifi,但是小米wifi对应的客户端不是很好用,动不动就启动失败,不要问 ...