题目链接:

https://vjudge.net/problem/POJ-2229

题目大意:

给定一个N,只允许使用2的幂次数,问有多少种不同的方案组成N。

思路:

处理出2的幂次方的所有的数字,当做物品,每个物品次数不限,求凑出体积为N的方案数

类似完全背包,先枚举物品,再正序枚举体积,转移状态dp[i][j]表示前i件物品凑出的体积为j的方案数

dp[i][j] = dp[i - 1][j] + dp[i - 1][j - w[i]]

 #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m, minans;
const int maxn = 1e6 + ;
const int mod = 1e9;
int dp[maxn];
int w[], tot;
int main()
{
cin >> n;
for(int i = ; (<<i) <= n; i++)
{
w[tot++] = (<<i);//构造出所有物品
}
//完全背包,dp[i][j]表示前i件物品凑成j体积的方案数
//dp[i][j] = dp[i - 1][j] + dp[i -1][j - w[i]];
dp[] = ;
for(int i = ; i < tot; i++)
{
//完全背包,正序
for(int j = w[i]; j <= n; j++)
dp[j] = (dp[j] + dp[j - w[i]]) % mod;
}
cout<<dp[n]<<endl;
return ;
}

POJ-2229 Sumsets---完全背包变形的更多相关文章

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

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

  2. poj 2229 【完全背包dp】【递推dp】

    poj 2229 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 21281   Accepted: 828 ...

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

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

  4. poj -2229 Sumsets (dp)

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

  5. POJ 2229 Sumsets

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

  6. poj 2229 Sumsets(dp)

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

  7. POJ 2923 Relocation(01背包变形, 状态压缩DP)

    Q: 如何判断几件物品能否被 2 辆车一次拉走? A: DP 问题. 先 dp 求解第一辆车能够装下的最大的重量, 然后计算剩下的重量之和是否小于第二辆车的 capacity, 若小于, 这 OK. ...

  8. POJ 2229 sumset ( 完全背包 || 规律递推DP )

    题意 : 给出一个数 n ,问如果使用 2 的幂的和来组成这个数 n 有多少种不同的方案? 分析 :  完全背包解法 将问题抽象==>有重量分别为 2^0.2^1.2^2…2^k 的物品且每种物 ...

  9. poj 2229 Sumsets DP

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

  10. poj 2229 Sumsets(dp 或 数学)

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

随机推荐

  1. ZPL打印机公用代码

    using System;using System.Collections.Generic;using System.Linq;using System.Web; using System.Text; ...

  2. C3算法 和 super

    一. Python的继承  多继承 子类继承父类. 继承是为了节省开发时间.提高开发效率 代码得到了重(chong)用 一个类可以拥有多个父类 lass shen_xian: # 定义一个神仙类 de ...

  3. jconsole如何查看

    https://www.jdon.com/idea/jvm-gc.html 场景: https://www.cnblogs.com/yszzu/p/9648579.html    查看大对象到底占用多 ...

  4. 第一章javascript简介

    javascript 当诞生于1995 最开始是目的是处理在服务器端进行的表单验证:让其在服务器端验证改为在服务端验证,大大提高速度(当时网络慢) 如今javascript是一门功能全面的语言,包含闭 ...

  5. kubernetes命令补全

    # yum install -y bash-completion # locate bash_completion /usr/share/bash-completion/bash_completion ...

  6. ie中html页面无法加载css

    今天写代码发生一个很尴尬的问题,码了一天的代码在ie下一调试居然没有样式,打开F12查看元素果然没有样式,在其他浏览器完全没问题,ie就出事. ie肯定没问题,问题还是处在代码上了,百度了一下说是把& ...

  7. OpenStack概念

    OpenStack is a global collaboration ofdevelopers and cloud computing technologists producing the ubi ...

  8. 解决 eclipse cdt 运行时控制台乱码解决

    1 点击黑色 倒三角 按钮 选择 run configurations 2 2.1 点击new 添加 LANG = en_US 2.2 选择 replace native environment wi ...

  9. HDU 4342——History repeat itself——————【数学规律】

    History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  10. PHP设计原则

    Laravel   PHP设计模式 定义:将PHP设计成一个固化的模式 面向对象设计原则 内聚度:高内聚,表示一个应用程序的单个单元所负责的任务数量和多样性.内聚与单个类或者单个方法单元相关 耦合度: ...