【HDU5951 2016ACM ICPC亚洲区沈阳站-重现赛 D】【博弈 DP】Recursive sequence n物品A元B元连续竞价的平衡点
来源:互联网 发布:石头网络刷钻软件 编辑:程序博客网 时间:2024/06/07 23:57
Winning an Auction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 47 Accepted Submission(s): 3
Problem Description
Alice and Bob play an auction game. Alice has A dollars and Bob has B dollars initially. There are N items on sale. In each round, an item will be sold by the following way. Alice writes down an integer a (0 ≤ a ≤ A) and Bob writes down an integer b (0 ≤ b ≤ B), which are the amount of dollars they want to pay for the item. If a > b, then Alice gets the item and pays a dollars to the seller. If a < b, then Bob gets the item and pays b dollars to the seller. If a = b, then for the 1st, 3rd, 5th, 7th ... round, Alice gets the item and pays a dollars; for the 2rd, 4th, 6th, 8th ... round, Bob gets the item and pays b dollars. Since all the items have the same value, the goal of the auction game is to get as many items as possible. Both Alice and Bob know the values of N,A and B. Your task is to calculate how many items they will get if both of them play optimally.
Input
The first line is the number of test cases. Each test case contains 3 integers N,A and B, which are no larger than 255.
Output
For each test case, output the number of items Alice and Bob will get if both of them play optimally.
Sample Input
31 1 22 4 23 3 3
Sample Output
Alice 0 Bob 1Alice 1 Bob 1Alice 2 Bob 1
Source
2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
//http://blog.csdn.net/snowy_smile/article/details/52981616#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;#define MS(x, y) memset(x, y, sizeof(x))#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }const int N = 256, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }int casenum, casei;int n, A, B;short f[2][N][N][N];void DP(){ for (int o = 0; o < 2; ++o) { for (int a = 0; a <= 255; ++a) { for (int b = 0; b <= 255; ++b) { if (a > b)f[o][1][a][b] = 1; else if (b > a)f[o][1][a][b] = 0; else f[o][1][a][b] = o == 1 ? 1 : 0; } } } for (int o = 0; o < 2; ++o) { for (int p = 2; p <= 255; ++p) { for (int a = 0; a <= 255; ++a) { for (int b = 0; b <= 255; ++b) { if (a == b) { if (p & 1)f[o][p][a][b] = p / 2 + (o == 1); else f[o][p][a][b] = p / 2; continue; } if ((o - p + 1) & 1)//Alice占据优势 { int va = f[o][p - 1][a][b] + 1; //初始a买的状态 int vb; for (int u = 1; ; ++u) { if (b < u || (vb = f[o][p - 1][a][b - u]) >= va) //b多花钱没意义 { f[o][p][a][b] = va; break; } if (a < u || (va = f[o][p - 1][a - u][b] + 1) <= vb)//a多花钱没意义 { f[o][p][a][b] = vb; break; } } } else//Bob占据优势 { int vb = f[o][p - 1][a][b]; //初始b买的状态 int va; for (int u = 1; ; ++u) { if (a < u || (va = f[o][p - 1][a - u][b] + 1) <= vb)//a多花钱没意义 { f[o][p][a][b] = vb; break; } if (b < u || (vb = f[o][p - 1][a][b - u]) >= va) //b多花钱没意义 { f[o][p][a][b] = va; break; } } } } } } }}int main(){ DP(); scanf("%d", &casenum); for (casei = 1; casei <= casenum; ++casei) { scanf("%d%d%d", &n, &A, &B); int Alice = f[n & 1][n][A][B]; int Bob = n - Alice; printf("Alice %d Bob %d\n", Alice, Bob); } return 0;}/*【trick&&吐槽】1,记忆化搜索是比DP慢一些,甚至可能达到2倍常数,所以记忆化搜索这里会TLE儿DP可以AC2,使用short类型才可以满足这种做法的空间要求3,如果离线询问的话是可以对空间再次降低一半的【题意】http://acm.hdu.edu.cn/showproblem.php?pid=5951【分析】用f[o][i][j][k]表示初始n的奇偶性为o,现在考虑到倒数第i件物品,Alice还剩下j元钱,Bob还剩下k元钱对于第1 ~ i的所有物品,Alice在最优策略下所能获得的最大物品数。那么我们可以从0开始枚举物品的实际购买价格。例如假设现是Alice的奇偶性优势点,Alice可以以x元购买这个物品,那么Alice的收益会是f[o][i - 1][j - x][k] + 1而Bob如果以x + 1元购买这个物品,使得Alice的收益会是f[o][i - 1][j][k - x - 1]如果Bob的这个"x + 1元购买"的决策,相比于Alice的"x元购买"策略,能使得Alice的收益变少,则Bob肯定会花这x + 1元同理,如果Alice的"x + 1"元购买策略,相比于Bob的"x + 1元购买策略",能使得Alice的收益增加,则Alice肯定会花这x + 1元……两人一直进行到,其中一人无力出更高价或者即使出更高价也不优。【时间复杂度&&优化】O(2 * n ^ 3 * k)*/
1 0
- 【HDU5951 2016ACM ICPC亚洲区沈阳站-重现赛 D】【博弈 DP】Recursive sequence n物品A元B元连续竞价的平衡点
- HDU 5950 Recursive sequence(2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
- HDU 5950 Recursive sequence(构造矩阵+矩阵乘法)——2016ACM/ICPC亚洲区沈阳站(重现赛)
- 2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) 1003Recursive sequence(题解)
- 【HDU 5950】【构造矩阵+矩阵幂】 Recursive sequence——2016ACM/ICPC亚洲区沈阳站(重现赛)
- 【HDU5950 2016ACM ICPC亚洲区沈阳站-重现赛 C】【矩阵快速幂】Recursive sequence 矩阵递推 i ^ 4
- Hdoj Recursive sequence 2016ACM/ICPC亚洲区沈阳站 【矩阵加速状态转移】
- 2016ACM/ICPC亚洲区沈阳站1003题 Recursive sequence +构造矩阵+矩阵连乘
- 2016ACM-ICPC亚洲区沈阳站 C-Recursive sequence 矩阵快速幂
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
- 2016ACM/ICPC亚洲区沈阳站 C Recursive sequence (矩阵快速幂)
- HDU 5512 Pagodas (GCD博弈 + 2015ACM/ICPC亚洲区沈阳站-重现赛)
- HDU 5950 Recursive sequence(构造矩阵+矩阵幂)——2016ACM/ICPC亚洲区沈阳站
- HDU 5952 Counting Cliques(2016ACM/ICPC亚洲区沈阳站-重现赛)
- 2016ACM/ICPC亚洲区沈阳站-重现赛 部分题解
- HDU 5974 A Simple Math Problem(2016ACM/ICPC亚洲区大连站-重现赛 D题)
- hdu5512 Pagodas(2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学) )
- 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)HDU5512 Pagodas
- 文字超出变为省略号
- 蓝桥杯-鸡兔同笼问题(例题)
- 密码学基础知识
- android开发修改项目字体
- POj 2002 UVALive - 3047 C - Squares 【计算几何+二分求解】
- 【HDU5951 2016ACM ICPC亚洲区沈阳站-重现赛 D】【博弈 DP】Recursive sequence n物品A元B元连续竞价的平衡点
- CSS3 Filter的十种特效
- Days40 MaterialDesign(一)
- android 系列问题记录
- 【14.67%】【codeforces 615D】Multipliers
- Definition of "containing block" 细说包含块
- 利用QPalette给窗体设置背景图片
- 如何为我们的Ubuntu Core应用进行设置
- 半导体三极管及其应用(一)