题目链接:

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. java拦截器的使用

    转载: https://www.cnblogs.com/liangblog/p/7234757.html https://blog.csdn.net/reggergdsg/article/detail ...

  2. centos7-网络与防火墙常用命令

    1.网络配置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="static" IPADDR=192.168.163 ...

  3. PHP、thinkPHP5.0开发网站文件管理功能(三)重命名文件

    public function renames(){ if(request()->isAjax()){ $file = iconv('UTF-8','GB2312',urldecode(inpu ...

  4. 15-----BBS论坛

    BBS论坛(十五) 15.1.登录界面完成 (1)front/signbase.html {% from 'common/_macros.html' import static %} <!DOC ...

  5. Win 10 Enable .net framework 3.5 error (Error code:0x800F081F )

    在下面页面enable .net frramwork 3.5时,发生0x800F081F错误. 解决方案: 1. 在如下链接下载Win10 版的microsoft-windows-netfx3-ond ...

  6. Spring注入的反射解释

    对于如下配置片段:  <bean id="id" class="lee.Aclass">  <!--property配置需要依赖注入的属性-- ...

  7. Android NDK开发 字符串(四)

    几个概念首先要明确: java内部是使用16bit的unicode编码(UTF-16)来表示字符串的,无论中文英文都是2字节: jni内部是使用UTF-8编码来表示字符串的,UTF-8是变长编码的un ...

  8. Redis Intro - Dict

    https://segmentfault.com/a/1190000004850844

  9. Mongodb~连接串的整理

    mongodb连接串可以分为普通开放的,带全局用户名和密码的,为指定数据库指定用户名密码的等. 普通开放连接 mongodb://localhost:27017 带全局用户密码的 mongodb:// ...

  10. mac os 和 ubuntu 上测试工具check-0.9.10的安装

    由于工作需要,要使用check 这个单元测试工具. 首先,说一说在Mac10.9上面的安装.我是直接在官网(http://check.sourceforge.net)上下载源码包. 1,解压 2,进入 ...