uva 10404 Bachet's Game(完全背包)】的更多相关文章

题目连接:10404 - Bachet's Game 题目大意:由一堆石子, 给出石子的总数, 接下来由stan和ollie两个人玩游戏,给出n, 在给出n种取石子的方法(即为每次可取走石子的数量),由stan先,两人轮流取走石子,最后一个将石子全部去完的人胜利,问, 给出的一堆石子, 两人均按最好的方案游戏, 最后将会是谁胜 ? 解题思路:问题可以看做是一个完全背包的变形, dp[i]只有0 和1两种状态, 1 是代表当前i个石子先取者为必胜, 0 带表当前n个石子先取者为必败.转态转移方程i…
Problem B: Bachet's Game Bachet's game is probably known to all but probably not by this name. Initially there are  n  stones on the table. There are two players Stan and Ollie, who move alternately. Stan always starts. The legal moves consist in rem…
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态转移方程 dp[j+c[i]] = dp[j] + dp[j+c[i]] 代码总览 /* Title:UVA.674 Author:pengwill Date:2017-2-16 */ #include <iostream> #include <cstdio> #include <…
题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum,   A,B其中必有一人获得的钱小于等于sum/2,另一人获得的钱大于等于sum/2.   因此用sum/2作为背包容量对n个硬币做01背包处理,   所能得到的最大容量即为其中一人获得的钱数. #include <iostream> #include <cstdio> #include <cstring> #includ…
Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, likes eating Krusty-burgers. It takes Homer m minutes to eat a Krusty- burger. However, there�s a new type of burger in Apu�s Kwik-e-Mart. Homer likes…
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great lengt…
https://vjudge.net/problem/UVA-674 题意: 计算兑换零钱的方法共有几种. 思路: 完全背包基础题. #include<iostream> #include<string> #include<cstring> #include<algorithm> using namespace std; ]; ] = { , , , , }; int main() { //freopen("D:\\txt.txt", &…
https://vjudge.net/problem/UVA-12563 题意: 在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间. 思路: 0-1背包问题,背包容量为t-1,因为至少还要留1秒钟来放劲歌金曲.还需要注意的是题目要求的是在唱最多首歌的情况下所能唱的最长时间,所以这里我们来限制一下时间,对于j时刻,我们要求正好唱完这首歌,那么这样唱的歌肯定是最多的. #include<iostream> #include<algorithm> #incl…
It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great length and thus crea…
题目: 思路: dp[j][h]表示选取了j个向量,且高度为h,利用01背包来解决问题. 没选当前的向量:dp[j][h] = dp[j][h]; 选了当前的向量:dp[j][h] = dp[j-1][h-p[i].y]+2*p[i].x*(h-p[i].y)+p[i].area;(p[i].area = p[i].x+p[i].y) 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1000000000 #defi…