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

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. apache server和tomcat集群配置一:水平负载

    下载apache  server,最新链接http://archive.apache.org/dist/httpd/binaries/win32 当前实验版本2.2.4 下载apache  tomca ...

  2. OpenCV笔记 1

    Structure  Contains  Represents CvPoint int x, y  Point in image CvPoint2D32f float x, y  Points in ...

  3. ssh整合思想

    整合过程:

  4. 一堵墙IFC数据-wall.ifc

    这是一面墙的IFC数据内容 =====================================文档内容======================================= ISO-1 ...

  5. redis 有用

     浅谈redis   (1)什么是redis? Redis 是一个基于内存的高性能key-value数据库. (有空再补充,有理解错误或不足欢迎指正)   (2)Reids的特点 redis本质上是一 ...

  6. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-004计算内存

    1. 2. 3.字符串

  7. hdu4283 You Are the One

    传送门 题目 The TV shows such as You Are the One has been very popular. In order to meet the need of boys ...

  8. $this->autoRender = false

    动作执行完之后禁止调用render()方法

  9. 手把手教Android商业项目-即时通讯-i美聊

    [课程概况] 手把手教你从无到有的完整实现一个Android商业项目,是目前整个市场上所没有的课程,废话不多说,请往下看. [项目概况] 项目名称:i美聊 所属领域:移动社交 即时通讯   代码行数: ...

  10. DingTalk机器人C#代码

    前面已经介绍了机器人的事情,今天直接贴一下代码. using System; using System.Collections.Generic; using System.ComponentModel ...