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 ...
随机推荐
- crt连接vitualbox中centos虚拟机
在virtalbox中安装了centos虚拟机后,在虚拟机中直接操作很是不方便,所以想用crt连接虚拟机, 1.打开virtualbox,设置-网络,网络连接2设置连接方式为“Bridged Adap ...
- 网页往数据库里插数据要用utf8,否则就乱码
把网页的这行<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ...
- Oracle分区知识
查询分区名称.表空间的SQL USER_SEGMENTS SELECT SEGMENT_NAME,PARTITION_NAME,TABLESPACE_NAME FROM USER_SEGMENTS; ...
- 什么是PCB改板及PCB改板应注意的问题
PCB改板是指在保持原有功能一致的前提下,对原有产品设计及电路板布局走线设计的基础上进行整改设计,调整板上器件布局与线路走向,实现电子产品重新设计研发,同时又可以规避知识产权等纠纷,加快新产品研发速度 ...
- Qt实战之开发软件数据获取助手(eventFilter处理鼠标按下,event处理鼠标松开)
前段时间,受朋友委托,需要做一个能够获取别人软件文本框中内容的助手.当然这需要调用win api来解决问题.一开始,我想都没想,就用getWindowText()....居然没用,好郁闷.于是查msd ...
- Node.mongoose
简介 mongodb是一款面向文档的数据库,不是关系型数据库,新手熟悉mysql.sqlserver等数据库的人可能入手稍微困难些,需要转换一下思想,可以不需要有固定的存储模式,以文档模型为存储内容相 ...
- Shot(三分)
Shot Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- vmware 几种联网的方式,怎样实现虚拟机上网
我的pc有一个IP地址是可以訪问网络的,那么如何让VM可以共享我的IP地址,也能上网呢.今天在摸索中实现了,详细的配置例如以下: 1,首先将VM的网卡net8启用: 2,然后将VM的网卡设置为VMne ...
- DBV-00111: OCI failure (3722) (ORA-01002: fetch out of sequence解决
在使用DBV检测segment的时候出现 DBV-00111: OCI failure (3722) (ORA-01002: fetch out of sequence)错误: 在寻找原因过程中发现相 ...
- asp.net传值
asp.net页面传至几种方法 Response.Redirect (或称 Query String 方式.URL方式) Response.Redirect("WebForm5.aspx&q ...