题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 问题描述 Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across th…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3869    Accepted Submission(s): 1237 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3339 In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7869    Accepted Submission(s): 2674 Problem Description Since 1945, when the first…
思路:最短路求出到每个点的最小代价,然后01背包,求出某一代价所能拿到的最大价值,然后搜索最后结果. 代码: #include<cstdio> #include<set> #include<cmath> #include<stack> #include<cstring> #include<string> #include<sstream> #include<iostream> #include<algor…
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5951    Accepted Submission(s): 1998 Problem Description Since 1945, when the firs…
 Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe. Nowadays,the crazy boy in FZU named AekdyCoin possesses some nuclear weapons and wanna destroy…
In Action Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3339 Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5102    Accepted Submission(s): 1696 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
http://acm.hdu.edu.cn/showproblem.php?pid=3339 这道题就是dijkstra+01背包,先求一遍最短路,再用01背包求. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 100000 using namespace std; <<; int n,m,st,ed,c; int dis[maxn]; bool vis[maxn…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5534 题解:这题一看有点像树形dp但是树形dp显然没什么思路.然后由于这里的约束几乎没有就是一颗树然后是任意组合,但是有一点总的度数是2*n-2这是不变的,然后就是选择度数为1,2,3....n-1的点的组合,这么说说是不是有点像背包,然后可以想一下一开始所有点的度数都为1然后就是n*f[1]如果要组成一个度数为2的话只需要剪掉一个度数为1的也就是说f[1]然后加上f[2]即可,这样就很…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: 给定\(a_1,a_2,...,a_n\)和\(K\),求使得\(\sum^{n}_{i=1}a_ix_i=B\)有正整数解且\(B\ge K\)的最小\(B\)值.在本题中\(n=4, a_i\le 30000, K\le 10^{18}\). 这好像是个最短路经典问题,但是我想了三小时根本没想到…
HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置(i,j)有一个容量为k的背包所能获得的最大价值 决策:a[i][j]处的数是否选取 不选取: dp[i][j][k]= max(dp[i-1][j][k], dp[i][j-1][k]) 选取:首先要求k >=a[i][j],那么dp[i][j][k] = max(dp[i-1][j][k-w[i…
HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N (N<32768) 兑换成硬币有非常多种兑法. 请你编程序计算出共同拥有多少种兑法. 分析:基础的全然背包问题. 本题限制条件是: 金钱总数<=N. 本题目标条件是: 求构造方法数目. 令dp[i][j]==x 表示用前i种硬币构造j 美分共同拥有x种方法. 初始化:  dp为全0且dp[0][0]…
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 505 #define nn 505*100 using namespace std;…
HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为这时候还剩下5块钱,直接买最贵的那个菜,就可以保证剩下来的钱数是最小的. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nma…
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 1005 using namespace std; int v[nmax],w[nmax],dp[nmax]; int main() { //freopen("in…
HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有cost[i]花费和val[i]价值, 你有m元钱, 如今问你最多能买多少总价值的物品? 当中N<=10W, m<=1W. 且cost[i]和val[i]都在[0,10]范围. 分析: 本题初看直接用01背包来做是直观的想法. 可是考虑到01背包的复杂度为O(N*m), 这么大的复杂度肯定不行. 然…
HDU 1864 最大报销额 0-1背包 题意 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元.现请你编写程序,在给出的一堆发票中找出可以报销的.不超过给定额度的最大报销额. 这里要注意的是,只要总金额大于1000,或者每种类别的总金额大于600,或者这个发票中有其他类别物品,就不能报销 解题思路 这里就是简单的\(0-1\)背包了,主要的就是在于对于数据的预处…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5220    Accepted Submission(s): 1745 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe. Nowadays,th…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave…
题意:从A走到B,有最短路,问这样不重复的最短路有几条 思路:先来讲选有效边,我们从start和end各跑一次最短路,得到dis1和dis2数组,如果dis1[u] + dis2[v] + cost[u][v] == dis1[end],那么uv这条边是最短路的一条边.然后我们选完边,把边加入ISAP,然后跑一边就行了...还没学过SAP只会敲模板.... 错误思路:刚开始想的是先求出最短路,然后用费用流spfa去跑,边容量1,如果跑出一条路径费用等于最短路,那么路径+1,继续跑,但是超时了,看…
思路:虽然是最短路专题里的,但也很难想到是最短路,如果能通过这些关系想到图论可能会有些思路.我们把X数组看做邻接矩阵,那么三个条件就转化为了:1.1的出度为1:2.n的入度为1:3.2~n-1的出度等于入度.C*X则是路径花费,最后求满足这些条件的路径的最少花费.满足这些条件的情况有两种:一是1到n的一条最短路径,二是1成自环,n成自环.最后找出两者最小值. 这里要注意下spfa的写法,因为需要成自环,所以dist[st]初始化为INF,保证成自环而非0:先让其他点入队. 代码: #includ…
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家都希望尽量使卡上的余额最少.某天,食堂中有n种菜出售,每种菜可购买一次.已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少. Input 多组数据.对于每组数据:第一行为正整数n,表示菜的数量.n<=1000.第二行包括n个正整数,表示每种菜的价格.价…
最短路+01背包 In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3857    Accepted Submission(s): 1229 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan…
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33.(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词). 题解:把26个字母看做26种背包,有个数有价值,求价值不超过50的所有可能个数,就是标准的多重背包.…
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4720 Accepted Submission(s): 1553 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team i…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5294 题意: 给你个无向图: 1.求最少删除几条边就能破坏节点1到节点n的最短路径, 2.最多能删除多少条边同时保证1到n的最短距离不变. 题解: 首先用spfa或dijcstra跑出所有最短路组成的DAG图. 用这个图跑最大流节能解决第一个问题,用这个图跑一遍bfs最短路就能解决第二个问题. 然而我在跑最大流的时候竟然把DAG图建成双向的了orz.. 代码: #include<iostream>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32136    Accepted Submission(s): 15965 Problem Description Before ACM can do anythi…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 Partychen like to do mathematical problems. One day, when he was doing on a least common m…