shu7-19【背包和母函数练习】】的更多相关文章

Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三种解法: 多重背包的优化与否:(1031MS) #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; ]; ],b[];…
ps:原来用新浪,可是代码的排版不是很好,所以用博客园啦,先容许我把从八月份开始的代码搬过来,从这里重新出发,希望这里可以一直见证我的成长. Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9186    Accepted Submission(s): 5591 Problem Description 在一个国家仅有1分,2分,3分硬币,…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2079 题意:同样的学分 ,有多少种组合数,注意同样学分,课程没有区别 思路:两种方法 背包 母函数 背包: 注意初始化时dp[0]=1,其他都为0,循环时从学分N开始更新,减到为0,表示成功,组合数加一. 代码: #include <iostream> using namespace std; int main () { ]; //dp记录当前学分的组合数 cin>>t; while(t-…
题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083 密码:shuacm 感觉他们学校的新生训练出的比较好. 今天很多题目都是强化了背包的转化. 关于背包转化成求最优解见分析:点击打开链接 贴个背包的模板: //0-1背包, 代价为 cost, 获得的价值为 weight // 每种物品最多只可以选一次 void ZeroOnePack(int cost, int weight) { for(int i = nValue; i >= co…
题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对应6种价钱的石头数目,比如101200代表价值为1的石头有1个,价值为2的石头有0个....价值为4的石头有2个.他们具有的石头数量的上限为2万个. 思路: 想用多重背包的方式解决,也想转01背包比较简单.直接转01背包会超时,得想办法.可以用多重背包的方法,用二进制来减少复杂度,应该可行.我用的是…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51181    Accepted Submission(s): 17486 Problem DescriptionNowadays, we all know that Computer College is the biggest department…
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big…
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41 Accepted Submission(s): 29   Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disap…
题意: N=a[1]+a[2]+a[3]+...+a[m];  a[i]>0,1<=m<=N; 例如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; 共有5种. 给N,问共有几种构造方式. 思路: 一个数N分解的式子中1的个数可以是0,1,2,3,...,N. 2的个数可以是0,1,2,...,N/2. .... 母函数基础题,, 看代码. 当然也可以用DP(背包) 母函数代码: int N,num;…
与 HDU 1028 相似的题目. 方法一:完全背包. 限制条件:硬币总值不超过 n. 目标:求出组合种数. 令 dp[ i ][ j ] == x 表示用前 i 种硬币组合价值为 j 的钱共 x 种方法. 状态转移方程:dp[ i ][ j ] = dp[ i - 1][ j ] + dp[ i ][ j - v[ i ] ] : 方程解释:用前 i 种硬币组合出钱 j 的方法数 = 前 i - 1 种硬币组合出钱 j 的方法数(不用第 i 种硬币)+ 至少用一枚第 i 种硬币的方法数. 滚动…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24708    Accepted Submission(s): 8700 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23728    Accepted Submission(s): 8363 Problem Description Nowadays, we all know that Computer College is the biggest department…
http://acm.hdu.edu.cn/showproblem.php?pid=2110 就是个多重背包,有坑点-.-.注意答案模10000中间结果有可能会爆所以计算时就要取模: 由于必须能均分三份所以总价值肯定能除尽3,只要计算出1/3总价值的方案数即可,也就是2/3总价值的方案数: #include<iostream>#include<cstring>#include<cstdio>using namespace std;#define inf 0x3f3f3f…
Time limit per test: 2.0 seconds Memory limit: 512 megabytes 唐纳德先生的某女性朋友最近与唐纳德先生同居.该女性朋友携带一 baby.该 baby 酷爱吃棒棒糖,且有一个奇怪的特性:今天吃的棒棒糖一定要比昨天的棒棒糖更多,至少要一样多.如果棒棒糖少了,baby 就会很不高兴:另外如果有连续 k 天棒棒糖的数量都是一样的,baby 也会很不高兴. 唐纳德先生发现他的口袋里只有可怜的 n 元钱,他可以用 1 元钱买 1 根棒棒糖.他想用这些…
Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23277    Accepted Submission(s): 6616 Problem Description Marsha and Bill own a collection of marbles. They want to split the collection…
传送门 分组背包经典问题. 令f[i][j]f[i][j]f[i][j]表示前iii组花费为jjj的最优值. g[i][j]g[i][j]g[i][j]表示前iii组,第iii组已经支付了平台费用的最优值. 然后用ggg来转移f,gf,gf,g就行了. 代码…
早上随便搞搞t1t3就开始划水了,t2一看就是组合数学看着肚子疼...结果t1t3都a了??感天动地. 从小到大排序,从前到后枚举i,表示i是整个背包中不选的物品中代价最小的那个,即i不选,1到i-1全部都要选,i+1到n做背包(此时容量为m-pre),极限复杂度$O(n^3)$,可是我们在中间判断一下,当剩余容量比当前i代价小,break.可以减掉很大的复杂度!(cena评测最慢0.04s~ 或者可以在枚举i时倒着枚举,每次背包就可以$O(n)$解决了. #include<iostream>…
http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只需要选出>=n个即可. 一开始的时候想不到ti + 1,一直不知道能多选ti个后,本来是选了多少个. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #inc…
题目:这里 题意: 感觉并不能表达清楚题意,所以 Problem Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly one path. In other words, any connected graph without simple cycles is a…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1011 题目大意:树上取点,先取父亲,再取儿子.每个点,权为w,花费为cost,给定m消费总额,求最大权和. 解题思路: 树形背包模板题.首先建一个无向图. 每个点的cost=(bug[root]+19)/20,即虫子数不满20也要派一个人. 用dp[i][j]表示以i为根的子树中,花费为j的最大权和. 转移方程:dp[i][j]=max(dp[i][j],dp[i][j-k]+dp[t][k]),…
题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大,转而以v为下标,求出价值对应的最小体积,然后求出能够满足给出体积的最大价值. 经典题目,思路倒是挺简单的,就是初始化总觉得别扭...T_T大概,因为我要找的是最小值,所以初始化为maxn,就结了? 这个问题好像叫01背包的超大背包... 模拟一下样例吧! 1 5 15 // 初始化为dp[0] =…
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park along the river know as the River Walk. Margaritas may be purchased at many establishments along the River Walk from fancy hotels to Joe's Taco and Marga…
Description On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favour of the Euro. This changed the ease of paying, and not just internationally. A student buying a 68 guilder book before J…
题目大意:给一棵有根带点权树,并且给出容量.求在不超过容量下的最大权值.前提是选完父节点才能选子节点. 题目分析:树上的分组背包. ps:特判m为0时的情况. 代码如下: # include<iostream> # include<cstdio> # include<vector> # include<cstring> # include<algorithm> using namespace std; const int N=105; const…
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5534 Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly…
Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10632    Accepted Submission(s): 4230 Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One…
Euro Efficiency Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 12   Accepted Submission(s) : 3 Problem Description On January 1st 2002, The Netherlands, and several other European countries aban…
本文出自   http://blog.csdn.net/shuangde800 题目链接 : hdu-1011   题意 有n个洞穴编号为1-n,洞穴间有通道,形成了一个n-1条边的树, 洞穴的入口即根节点是1. 每个洞穴有x只bugs,并有价值y的金子,全部消灭完一个洞穴的虫子,就可以获得这个洞穴的y个金子. 现在要派m个战士去找金子,从入口进入.每次只有消灭完当前洞穴的所有虫子,才可以选择进入下一个洞穴. 一个战士可以消灭20只虫子,如果要杀死x只虫子,那么要x/20向上取整即(x+19)/…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 15045   Accepted: 5997 Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer…
pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值总和为n的方案数 分析:这题能够用母函数的思想,对300以内的值进行预处理就可以 也可用全然背包思想求300以内的方案数 母函数: #include<stdio.h> int main() { int c1[305],c2[305],i,j,k,n; for(i=0;i<=300;i++){…