ZOJ 2852 Deck of Cards DP
题意:
一一个21点游戏。
1. 有三个牌堆,分别为1X,2X,3X。
2. 纸牌A的值为1,纸牌2-9的值与牌面面相同,10(T)、J、Q、K的值为10,而而joke(F)的值为
任意大大。
3. 一一列牌要按顺序放入入三个牌堆中。当某个牌堆的值超过21点时,不能在放牌;如果某个牌堆的
总值为21点时,这个排队讲会被清空;joke放上后这个牌堆的值立立即变为21点。
4. 成功放上一一张牌得50美元;成功清空一一个牌堆讲得到100*牌堆号美元,即1X得100美元,2X得
200美元,3X得300美元。
5. 当任意一一堆都不能继续放牌,或者已经没牌时,游戏结束。
现在求一一列扑克牌通过某种方方式放最多能得多少美元。
思路:
四维DP,令dp[i][j][k][g]表示示放第i张牌时,1X堆的值为j,2X堆的值为k,3X的值为g时,最
多能拿到的钱。以1x为例,设v为当前牌的值,其转移方方程为 dp[i+1][j+v][k][g] =
max(dp[i+1][j+v][k][g], dp[i][j][k][g]+50),当 j < 21且 j + v != 21且 v !=
21 时。dp[i+1][0][k][g] = max(dp[i+1][0][k][g], dp[i][j][k][g]+50),当 j <
21且 v 为 joke,或者 j + v == 21。
当然可以利用用滚动数组降低空间消耗。 Solution by Sake
Source Code:
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; int dp[][][][], n, ans;
char c; int GetValue (char c) {
if (c >= '' && c <= '') {
return c - '';
} else {
if (c == 'A') return ;
if (c == 'T') return ;
if (c == 'J') return ;
if (c == 'Q') return ;
if (c == 'K') return ;
if (c == 'F') return ;
}
return ;
} int main(){
std::ios::sync_with_stdio(false);
int i, j, t, k, u, v, g, numCase = ; while (cin >> n) {
if ( == n) break;
memset (dp, -, sizeof (dp));
dp[][][][] = ;
ans = ;
for (i = ; i <= n; ++i) {
if (i < n) {
cin >> c;
} else {
c = ;
}
v = GetValue(c);
for (j = ; j < ; ++j) {
for (k = ; k < ; ++k) {
for (g = ; g < ; ++g) {
if (dp[i][j][k][g] == -) continue;
checkmax(ans, dp[i][j][k][g]);
if ((v == && j < ) || j + v == ) {
checkmax(dp[i + ][][k][g], dp[i][j][k][g] + );
} else if (j < ) {
checkmax(dp[i + ][j + v][k][g], dp[i][j][k][g] + );
} if ((v == && k < ) || k + v == ) {
checkmax(dp[i + ][j][][g], dp[i][j][k][g] + );
} else if (k < ) {
checkmax(dp[i + ][j][k + v][g], dp[i][j][k][g] + );
} if ((v == && g < ) || g + v == ) {
checkmax(dp[i + ][j][k][], dp[i][j][k][g] + );
} else if (g < ) {
checkmax(dp[i + ][j][k][g + v], dp[i][j][k][g] + );
}
}
}
}
memset (dp[i], -, sizeof (dp[i]));
}
cout << ans << endl;
} return ;
}
ZOJ 2852 Deck of Cards DP的更多相关文章
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- codeforces 744C Hongcow Buys a Deck of Cards
C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards
地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per ...
- [Swift]LeetCode914.一副牌中的X | X of a Kind in a Deck of Cards
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- X of a Kind in a Deck of Cards LT914
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- LeetCode - X of a Kind in a Deck of Cards
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- 914. X of a Kind in a Deck of Cards
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- [leetcode-914-X of a Kind in a Deck of Cards]
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- [LeetCode] 914. X of a Kind in a Deck of Cards 一副牌中的X
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
随机推荐
- c风格字符串函数
十一.C 风格字符串 1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat( ...
- .NET study collection links
Parameter Binding in ASP.NET Web API http://www.asp.net/web-api/overview/formats-and-model-binding/p ...
- js 中的bind函数
bind是Function.prototype中内置函数 作用是指定函数作用域 代码参考 http://blog.csdn.net/load_life/article/details/7200381 ...
- NET Core Docker部署
NET Core Docker部署 前言 在前面文章中,介绍了 ASP.NET Core在 macOS,Linux 上基于Nginx和Jexus的发布和部署,本篇文章主要是如何在Docker容器中运行 ...
- css3: css3选择器
--------------------css3选择器-------------------------css3属性选择器 ~~属性选择器基本上ie7+都支持,可以相对放心的使用 见: www.ca ...
- Delphi中取整函数Round的Bug解决
Delphi中 Round函数有个Bug一旦参数是形如 XXX.5这样的数时如果 XXX 是奇数 那么就会 Round up如果 XXX 是偶数 那么就会 Round down例如 Round(17. ...
- Noip2008提高组总结
Noip2008前三题是基础题,仔细一些都是可以AC的,第四题的证明很巧妙,但是看懂后代码其实很简单,感觉在这些大家都不屑去做的简单题中又学到了不少,四道题代码基本都是十几二十行就够了,渐渐感觉到,比 ...
- HDU 2962 Trucking
题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...
- c++复习(未完待续)
1.使函数不能在定义该函数的文件之外访问的方法: (1)声明函数为static(2)将函数放到无名名字空间中 namespace { void g() { ......... } }
- Intersection(poj)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13140 Accepted: 3424 Des ...