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

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

Source

 

#include <cstdio>
int a[1000005];
int mod=1e9;
int dp[355][355];
int main ()
{int i,n;
a[1]=1;
a[2]=2;
for(i=3;i<=1000000;i++)
if(i&1) a[i]=a[i-1];
else a[i]=(a[i-2]+a[i>>1])%mod;
while(~scanf("%d",&i))
{
printf("%d\n",a[i]);
}
return 0;
}

好经典的题目。居然a[2]忘记给值了~

POJ 2229 Sumsets的更多相关文章

  1. poj -2229 Sumsets (dp)

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

  2. poj 2229 Sumsets(dp)

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

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

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

  4. poj 2229 Sumsets DP

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

  5. poj 2229 Sumsets(dp 或 数学)

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

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

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

  7. POJ 2229 Sumsets【DP】

    题意:把n拆分为2的幂相加的形式,问有多少种拆分方法. 分析:dp,任何dp一定要注意各个状态来源不能有重复情况.根据奇偶分两种情况,如果n是奇数则与n-1的情况相同.如果n是偶数则还可以分为两种情况 ...

  8. POJ 2229 Sumsets(技巧题, 背包变形)

    discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的 ...

  9. POJ 2229 Sumsets(规律)

    这是一道意想不到的规律题............或许是我比较菜,找不到把. Description Farmer John commanded his cows to search for diffe ...

随机推荐

  1. 【leetcode❤python】 278. First Bad Version

    #-*- coding: UTF-8 -*-# The isBadVersion API is already defined for you.# @param version, an integer ...

  2. Oracle(创建序列)

    概念: 所谓序列,在oracle中就是一个对象,这个对象用来提供一个有序的数据列,这个有序的数据列的值都不重复. 1.序列可以自动生成唯一值 2.是一个可以被共享的对象 3.典型的用来生成主键值的一个 ...

  3. 解决file_get_contents遇到中文文件名无法打开问题

    利用file_get_contents打开文件或采集远程服务器文件如果文名或url中碰到汉字中文那么会出现failed to open stream:Lnvalid argument in错误.   ...

  4. UDP主要丢包原因及具体问题分析

    UDP主要丢包原因及具体问题分析 一.主要丢包原因   1.接收端处理时间过长导致丢包:调用recv方法接收端收到数据后,处理数据花了一些时间,处理完后再次调用recv方法,在这二次调用间隔里,发过来 ...

  5. html,css命名规范 (转)

    HTML+CSS命名规范总结 1.HTML部分 1.1添加必须的utf-8的字符集,并且使用HTML5的简洁 方式: <meta charset="utf-8"> 1. ...

  6. getRuntime

    private static void test() { try { Process process = Runtime.getRuntime().exec("cmd"); Dat ...

  7. Node聊天程序实例06:server.js

    作者:vousiu 出处:http://www.cnblogs.com/vousiu 本实例参考自Mike Cantelon等人的<Node.js in Action>一书. server ...

  8. application、viewstate、纯HTML提交方式

    Application - 全局公共变量组 存放位置:服务端 所有的访问用户都是访问的同一个变量 声明周期:永久 用法同session类似 viewstate-病例 因为http的无状态性,需要记录上 ...

  9. MFC编程入门之二十三(常用控件:按钮控件的编程实例)

    上一节讲了按钮控件Button.Radio Button和Check Box的基本用法,本节继续讲按钮控件的内容,通过一个实例让大家更清楚按钮控件在实际的软件开发中如何使用. 因为Button控件在前 ...

  10. YYYY-mm-dd HH:MM:SS

    备忘:YYYY-mm-dd HH:MM:SS部分解释 d               月中的某一天.一位数的日期没有前导零.    dd             月中的某一天.一位数的日期有一个前导零 ...