zoukankan      html  css  js  c++  java
  • 1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 626  Solved: 348
    [Submit][Status]

    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).

    给出一个N(1≤N≤10^6),使用一些2的若干次幂的数相加来求之.问有多少种方法

    Input

       一个整数N.

    Output

    方法数.这个数可能很大,请输出其在十进制下的最后9位.

    Sample Input

    7

    Sample Output

    6

    有以下六种方式
    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

    HINT

     

    Source

    Silver

      题解:呵呵呵呵,又是一道DP题,显然,当n为奇数时,a[n]=a[n-1],当n为偶数时,a[n]=a[n-1]+a[n div 2](特别注意:题目中N的范围限制是6个0,一开始数组开的是5个0害得我RE了2次,记得mod 1000000000,还有最好a[0]设定为1,以防万一)

     1 var
     2    i,j,k,l,m,n:longint;
     3    a:array[0..2000000] of int64;
     4 begin
     5      readln(n);
     6      a[0]:=1;
     7      a[1]:=1;
     8      for i:=2 to n do
     9          begin
    10               a[i]:=a[i-1];
    11               if not(odd(i)) then a[i]:=(a[i]+a[i div 2]) mod 1000000000;
    12          end;
    13      writeln(a[n]);
    14 end.
  • 相关阅读:
    tone() 和 IRremote 冲突的解决办法
    Github
    bit Buffer
    转载:AAC文件解析及解码
    Z变换
    FFT
    DFT
    傅里叶变换
    傅里叶变换--虚部的理解
    转载:WAV header
  • 原文地址:https://www.cnblogs.com/HansBug/p/4163044.html
Copyright © 2011-2022 走看看