题目 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 toJoe’s Taco and Mar…
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…
题意 n个有体积的物品,问选取一些物品,且不能再继续选有多少方法? n<=1000 题解 以前的考试题.当时是A了,但发现是数据水,POJ上WA了. 把体积从小到大排序枚举没选的物品中体积最小的. 假设枚举到i,那么1到i-1一定都选.可选的空间为[m-sum[i-1]+1,m] 然后对于后面的数跑DP的到f[i][j]前i个数空间恰好为j时的方案: 贡献为可选空间的方案. 一个优化是倒着枚举i,这样在求f[i][j]时所花费的时间会大大减少. #include<iostream> #i…
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo…
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…
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit: 65536K 问题描述 Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contes…
题意:FJ身上有各种硬币,但是要买m元的东西,想用最少的硬币个数去买,且找回的硬币数量也是最少(老板会按照最少的量自动找钱),即掏出的硬币和收到的硬币个数最少. 思路:老板会自动找钱,且按最少的找,硬币数量也不限,那么可以用完全背包得出组成每个数目的硬币最少数量.而FJ带的钱是有限的,那么必须用多重背包,因为掏出的钱必须大于m,那么我们所要的是大于等于m钱的硬币个数,但是FJ带的钱可能很多,超过m的很多倍都可能,那么肯定要有个背包容量上限,网上说的根据抽屉原理是m+max*max,这里的max指…
题意: 给定身上的4种硬币,分别是1 ,5 ,10, 25面额各有多张,要求组成面额p的硬币尽可能多.输出组成p的4种硬币各自的数量. 思路: 多重背包,300+ms.用01背包+二进制的方法.记录下所有的硬币的个数以及4种硬币分别的个数,注意初始化dp数组的不同之处. #include <iostream> #include <cstdio> #include <cstring> #define LL long long using namespace std; ,…
\(Jury Compromise\) \(solution:\) 这道题很有意思,它的状态设得很...奇怪.但是它的数据范围实在是太暴露了.虽然当时还是想了好久好久,出题人设了几个限制(首先要两个的总和差值最小)(然后需要让它的总和最大).我们发现每一个人的顺序是无关紧要的,这其实又提示了我们可以背包.但我们发现很难设状态,我们需要让我们的总差值接近0,但是我们在加人的时候我们的总差值可能会增大也可能会减小,这不符合背包的基本要求,所以我们不能将总差值设为我们背包的权值.于是一个奇妙的想法产生…
http://poj.org/problem?id=1276 解题要点:用完全背包来模拟的解题,只不过加了限制条件used[]...其他的就一样了.. 注意: cash 和n 为0 的情况 #include <iostream> #include<cstring> using namespace std; int cash,n; ],w[]; ]; ]; int maxm(){ ||n==){ ; } ;i<=n;i++){ memset(used,,sizeof(used)…
题链: http://poj.org/problem?id=2125 题解: 最小割 + 输出割方案.建图:拆点,每个题拆为 i 和 i'分别表示其的入点和出点建立超源 S和超汇 T.S -> i :(outi[i]) 割了这个边相当于选择了 i-i'-> T :(ini[i])  割了这个边相当于选择了 i+u -> v':(INF)然后求Dinic跑最大流求最小割. 至于求方案,首先显然割的边都和 S或 T相连.从 S开始沿着非满载的边(包括反向边)dfs,对遇到的点打标记. 如果某…
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使得装入背包的总价值最大?*01 背包 *01 背包特点: 给定 n 种物品和一个背包 ( 每个物品只能选取一个).物品 i 的重量是w[i],其价值为v[i],背包的容量为C.应该如何选择装入背包中的物品,使得装入背包中的物品的总价值最大?*状态: dp[i][j] 表示在只能从 1-i 个物品中选…
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1019 Grandpa's Other Estate 1034 Simple Arithmetics 1036 Complete the sequence! 1043 Maya Calendar 1054 Game Prediction 1057 Mileage Bank 1067 Rails 10…
http://poj.org/problem?id=3683 思路:2-SAT,输出任意一组方案,O(m+n) #include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> ],next[],tot,go[]; ],Next[],Tot,Go[]; ],a[],n,ru[],low[],dfn[]; ],belong[],inst…
地址:http://poj.openjudge.cn/practice/C17K/ 题目: C17K:Lying Island 查看 提交 统计 提问 总时间限制:  2000ms 内存限制:  262144kB 描述 There are N people living on Lying Island. Some of them are good guys, while others are bad. It is known that good guys are always telling t…
HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #inc…
题目:http://poj.org/problem?id=3046 就是多重集组合数(分组背包优化): 从式子角度考虑:(干脆看这篇博客) https://blog.csdn.net/viphong/article/details/48110525 从意义的角度来考虑: 当 j<=a[i] 时,f[i][j] = f[i-1][j]  + f[i][j-1],就是分成了不选第 i 种物品和至少选一个第 i 种物品的情况,其中 f[i][j-1] 代表 j-1 后剩下的那一个物品一定是第 i 种:…
题目http://poj.org/problem?id=1276 分析 这是一个多重背包的问题,可以把请求的金额当作背包的重量,而货币的面值就是价值又是重量. 于是这个问题便很好理解背包了. #];;  ;  }  ZeroOnePack(amount],d[]; ;i,;i;}   来自为知笔记(Wiz)…
在一条街上有许多房屋,每间屋子里都住着人,并且都是做葡萄酒生意的商人,他们每天都要决定买卖多少瓶葡萄酒.有趣的地方是,供需总是完美地一致.商人总是能买到自己需要的葡萄酒,并且,他们从来不介意是从哪个商人那里购入的,只要求葡萄酒的搬运时间越少越好.如果把一瓶葡萄酒搬运到隔壁的成本是1,请求出全部葡萄酒买卖的最低搬运成本. 2. 输入和输出 输入数据由多行构成,每两行是一组测试数据.第一行是整条街上的店铺数n(2-100 000),第二行是n个整数,代表每间店面希望买卖的葡萄酒瓶数(?1 000-1…
Bridge Across Islands Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10455   Accepted: 3093   Special Judge Description Thousands of thousands years ago there was a small kingdom located in the middle of the Pacific Ocean. The territory…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数. 分析: 这道题不难想到n平方的算法,即从纵坐标最小的开始搜,每次找它前面横坐标的值比它小的点的个数,两个for循环搞定,但是会超时. 所以需要用一些数据结构去优化,主要是优化找 横坐…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…