Sumsets

直接翻译了

Descriptions

Farmer John 让奶牛们找一些数加起来等于一个给出的数N。但是奶牛们只会用2的整数幂。下面是凑出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

帮助FJ找到 N的分配数 (1 <= N <= 1,000,000).


Input

N


Output

排列方式总数。由于这个数可能很大,只需要保留最后9位


Sample Input

7

Sample Output

6

Hint

打表的会被系统自动识别判为WA

题目链接

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

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

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

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

1<<i 相当于 2i

AC代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 1000005
using namespace std;
int n;
int w[Maxn];
int cnt=;
int dp[Maxn];
int main()
{
scanf("%d",&n);
for(int i=;(<<i)<=n;i++)//构造所有物品
w[cnt++]=(<<i);
dp[]=;
for(int i=;i<cnt;i++)
for(int j=w[i];j<=n;j++)
dp[j]=(dp[j]+dp[j-w[i]])%;//取余 printf("%d\n",dp[n]);
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 2229 sumset ( 完全背包 || 规律递推DP )

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

  8. poj 2229 Sumsets DP

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

  9. poj 2229 Sumsets(dp 或 数学)

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

  10. poj 2229 Sumsets(记录结果再利用的DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 将一个数N分解为2的幂之和共有几种分法? 题解: 定义dp[ i ]为数 i 的 ...

随机推荐

  1. Python爬虫入门:爬取pixiv

    终于想开始爬自己想爬的网站了.于是就试着爬P站试试手. 我爬的图的目标网址是: http://www.pixiv.net/search.php?word=%E5%9B%9B%E6%9C%88%E3%8 ...

  2. 玲珑OJ 1083:XJT Love Digits(离线处理+哈希)

    http://www.ifrog.cc/acm/problem/1083 题意:比较好懂.注意答案的x不包含ax本身,所以才输出-1. 思路:离线处理.根据x排序,然后每次更新Hash[]数组就好了. ...

  3. Spring Boot 最流行的 16 条实践解读,你值得收藏!

    Spring Boot是最流行的用于开发微服务的Java框架.在本文中,我将与你分享自2016年以来我在专业开发中使用Spring Boot所采用的最佳实践.这些内容是基于我的个人经验和一些熟知的Sp ...

  4. Bzoj 1040 [ZJOI2008]骑士 题解

    1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5368  Solved: 2044[Submit][Status ...

  5. Q&A-Ray-20180710

    Q: 如果集群多个客户端订阅会不会重复接收消息? A: 集群环境用,有另外一个参数. NodeManager类没有在框架里面: public interface INodeManager : IGra ...

  6. 20140115-SqlHelper为什么是静态的

    为什么SqlHelper(或工具类)是静态的? 静态构造函数仅调用一次(即只是在程序生命周期中实例一次),在程序驻留的应用程序域的生存期内,静态类一直保留在内存中 这样可以减少每次使用的实例过程,就是 ...

  7. 20131207-ADO.NET-第十六天

    [1]快捷键 工具箱:ctrl+w+x 首字母定位控件范围 属性:F4 或ctrl+w+p Tab跳转 ,home 与end也有效 [2]连接字符串 string str = "Data S ...

  8. msf出现Database not connected等问题【已解决】

         kali启动msf后,出现Module database cache not built yet, using slow search,或是Database not connected,或是 ...

  9. 使用SVG symbols建立图标系统完整指南

    从最开始的使用img图片,到后来的使用css sprite来减少服务器请求,再到流行的图形字体化图标Iconfont.现在,一种全新的图标使用方式开始流行了起来--SVG symbols图标. 工作原 ...

  10. C#控制台打开VM虚拟机

    添加引用->VixCOM.dll (在vix文件夹下) VixWrapper.cs using System; using System.Collections.Generic; using S ...