zoukankan      html  css  js  c++  java
  • poj 2229 Sumsets

    题目链接http://poj.org/problem?id=2229

    题目分类:动态规划

    代码

    分析

    1

    1

    2

    1 1

    2

    3

    1 1 1 

    1 2

    4

    1 1 1 1

    1 1 2

    2 2

    4

    5

    1 1 1 1 1

    1 1 1 2

    1 2 2

    1 4

    6

    1 1 1 1 1 1

    1 1 1 1 2

    1 1 2 2

    1 1 4

    2 2 2

    2 4

    7

    1 1 1 1 1 1 1

    1 1 1 1 1 2

    1 1 1 2 2

    1 1 1 4

    1 2 2 2 

    1 2 4

    可以发现当n是奇数的时候,和n-1的情况是一样的。

    当你是偶数的时候  F(n)=F(n-2)+F(n/2)  

    F(n-2)代表每组数据中填2个1

    F(n/2)代表每个数据都乘以2  

    //#include<bits/stdc++.h>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    
    using namespace std;
    
    int n;
    #define MOD 1000000000
    
    __int64 dp[1000009]={0,1,2};
    
    void slove()
    {
        for(int i=3;i<=1000002;i++)
        {
            if(i%2)   //奇数
                dp[i]=dp[i-1];
            else      //偶数
            {
                dp[i]=dp[i-2]+dp[i/2];
                if(dp[i]>=MOD)
                    dp[i]%=MOD;
            }
        }
    }
    
    
    int main()
    {
        slove();
        scanf("%d",&n);
        printf("%I64d
    ",dp[n]);
        return 0;
    }
    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    jquery新知识
    jquery回顾
    Filter和Listener
    jsp,jstl,el
    cookie和session
    servlet和HTTP原理
    xml基本知识
    linux 相关操作
    linux mysql 相关操作、问题
    linux 文件结构
  • 原文地址:https://www.cnblogs.com/gaoss/p/4934666.html
Copyright © 2011-2022 走看看