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 ...
随机推荐
- 【LeetCode题意分析&解答】33. Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- HTML5 appcache
参考http://www.zation.me/2013/05/28/build_offline_mobile_web_app.html 他的事件总结的比较好 checking:客户端正在检查manif ...
- 部署vc2008开发的程序(vcredist_x86是其中一个办法)
如果你编译了一个VC2008的默认的CRT/MFC的应用程序,如果目标部署电脑上没有安装相应的VC2008的动态库,当运行你的程序的时 个,会出现如下错误信息. 这是因为程序使用了基于VC2008 ...
- Android Studio ADB响应失败解决方法
当启动Android Studio时,如果弹出 adb not responding. you can wait more,or kill "adb.exe" process ma ...
- Win32 GDI基础(笔记)
1.GDI名字的意义 GDI Graphic Device Interface,我说不清和GUI有什么区别.可能一种针对设备,一种针对用户而言吧,反正以后都说GDI,也就是Windows的图形编程. ...
- HDU 2393 Higher Math
#include <cstdio> #include <string> using namespace std; void swap(int& a,int& b ...
- commview for wifi 破解无线
相信了解无线网络的读者都知道安全性是无线网络的先天不足,正是因为他的传播通过空气,所以信号很容易出现外泄问题,相比有线网络来说信号监听变得非常简单. 部分用户通过WEP加密的方式来保护网络通讯数据包避 ...
- #, about:blank,javascript:路径比较
试了一下在<a>,<img>,<iframe>中用#,about:blank和javascript: 代码如下: <!Doctype html> < ...
- Cramfs、JFFS2、YAFFS2的全面对比
Cramfs.JFFS2.YAFFS2的全面对比http://blog.csdn.net/daofengdeba/article/details/7721340 由于嵌入式系统自身存在一些特殊要求,使 ...
- JavaSE学习总结第05天_Java语言基础1
05.01 方法概述和格式说明 简单的说:方法就是完成特定功能的代码块 在很多语言里面都有函数的定义,函数在Java中被称为方法 格式: 修饰符返回值类型方法名(参数类型参数名1,参数类型参数名2 ...