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

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. Solr 空间搜索配置、按经纬度计算距离排序

    Solr 空间搜索配置 1. 在solr目录下的找到conf文件夹下的schema.xml. <fields> <!-- 在fields元素中添加如下代码 --> <fi ...

  2. LaTeX 控制图片的位置

    加感叹号来忽略“美学”标准. \begin{figure}[!htb] \usepackage{float}\begin{figure}[H]插到你代码相应的位置. 1,插入并列的子图 \usepac ...

  3. springmvc 处理器方法返回的是string 重定向到处理器方法

  4. .NET回归 HTML----表单元素(1)和一些常用的标记

    表单就是-----用于搜集不同类型的用户输入. 表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. 首先将表单元素分为三个类型.文本类,按钮类,选择类. 表单可以嵌套在表中, ...

  5. Tensorflow练习

    # coding: utf-8 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # ...

  6. ubuntu下使用PIL中的show函数,无法显示图片的问题

    问题描述:ubuntu14.04系统,python2.7(version),正在学习python中, from PIL import Image im = Image.open('1.jpg') im ...

  7. php学习笔记-return语句

    一个函数中可以有return语句,也可以没有.什么时候需要呢?就是当你想接收函数的执行结果的时候,你需要一个return 语句. 函数执行完return语句之后,return语句后面的代码是永远不会得 ...

  8. linux环境安装python

    linux环境下安装python3,一步一步来吧! 安装python3 安装readline-devel依赖 ,用于解决python3安装完成后,退格和方向键乱码问题 yum install read ...

  9. 操作系统 Linux ex1 note

    ctrl + alt + T 命令行 ctrl + alt + F7 ctrl + alt + F1-6 ls 列出所有文件 / 根目录 ~ /home/username cd 切换路径 . 当前目录 ...

  10. Nor Flash工作原理

    http://blog.chinaunix.net/uid-26876150-id-3723678.html Nor Flash 具有像内存一样的接口,它可以像内存一样读,却不可以像内存一样写,Nor ...