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 ...
- DAO以及获取自动生成主键值
package com.alibaba.sql; import java.lang.reflect.InvocationTargetException; import java.sql.Connect ...
- MVC-04 视图(3)
五.Url辅助方法 Url辅助方法与HTML辅助方法很类似,HTML辅助方法用来产生HTML标签,而Url辅助方法则负责用来产生Url网址. @Url.Action("About" ...
- Spring Boot使用自定义的properties
spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,我们应该怎么做呢. 若继续在application.properties中添加 如: ...
- HDU 2178 猜数字
题解:设猜到的最大的数是h,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1. #include <cstdio& ...
- quartz搭建与应用
1.添加依赖 依赖包括Quartz和logback <dependencies> <dependency> <groupId>org.quartz-schedule ...
- tomcat使用所遇到的问题
1.在使用eclipse添加server的时候添加不了tomcat服务器: 如图左图所示,添加按钮已成灰色,无法操作. 解决办法:找到workspace的工作空间->.metadata-> ...
- pygame初步(一)绘制一个运动的矩形
<More Python Programming for the Absolute Beginner>一书中的第二章练习3(P33) 使用Python的Pygame库 import sys ...
- VMware: linux起步提示 memory for crashkernel(0*0 to 0*0)not within permissible
(virtualbox/VMware)linux起步提示memoryforcrashkernel(0*0 to 0*0)notwithinpermissible http://www.myexcep ...
- Python网络编程——修改套接字发送和接收的缓冲区大小
很多情况下,默认的套接字缓冲区大小可能不够用.此时,可以将默认的套接字缓冲区大小改成一个更合适的值. 1. 代码 # ! /usr/bin/env python # -*- coding: utf-8 ...