题目链接:

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. linux 数据库管理

    1.安装数据库: yum install mariadb.serversystemctl staus mariadbsystemctl start mariadbsystemctl enable ma ...

  2. Linux字符设备驱动--Led设备驱动

    ①驱动源码 #include <linux/module.h> #include <linux/init.h> #include <linux/cdev.h> #i ...

  3. 解决ifconfig没有网卡问题

    ifconfig -a root@kali:~# ifup eth0 ifup: unknown interface eth0 vim /etc/network/interfaces #自行添加网卡 ...

  4. java——最大堆 MaxHeap

    使用数组来实现最大堆 堆是平衡二叉树 import Date_pacage.Array; public class MaxHeap<E extends Comparable <E>& ...

  5. my.梦幻手游_XP

    1.http://my.netease.com/thread-459708-1-1.html 2. 3.

  6. 转 python 随机走动的模拟

    https://blog.csdn.net/python2014/article/details/21231971 麻省理工的随机走动模块,还不错,三天搞懂了,不过懂得不彻底.   记录下修改的代码 ...

  7. js学习笔记 -- 随记

    js不区分整数和浮点数,统一用Number表示, js'=='比较会自动转换类型,会产生奇怪结果,'==='不会转换比较类型,如果不一致返回false,因此js判断始终用'===' `` 保留换行,也 ...

  8. mysql中添加中文存储和显示功能

    1. 在 /etc/mysql/my.cnf中添加 [mysqld]character-set-server=utf8 [client]default-character-set=utf8 2. 检查 ...

  9. Spring Boot(一)Hello World

    Spring Boot适合与微服务,方便快速开发,简化配置(约定>配置). 准备工作: SpringBoot 2.0 jdk8 IDEA或者eclipse+Spring Tool Suits 创 ...

  10. pat1053. Path of Equal Weight (30)

    1053. Path of Equal Weight (30) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue G ...