题意:一个特殊21点游戏 具体http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2852

题解:建一个三维dp,表示三个卡槽分别为i,j,l分时最大的收益情况。

    对所有当前状态dp,将下一个可能的状态存入f,

坑:~-1==0

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<fstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
FILE *myfile;
myfile =freopen("C:\\Users\\SuuTT\\Desktop\\test\\in.txt", "r", stdin);
if (myfile == NULL)
fprintf(stdout, "error on input freopen\n");
/*FILE *outfile;
outfile= freopen("C:\\Users\\SuuTT\\Desktop\\test\\out.txt", "w", stdout);
if (outfile == NULL)
fprintf(stdout, "error on output freopen\n");*/
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int dir[][] = { ,,,,-,,,- };
const int maxn = 2e2 + ;
int f[][][], dp[][][]; int n; int ans;
int num(char c) {
if (c >= ''&&c <= '')return c - '';
else if (c == 'A')return ;
else if (c == 'F')return -;
else return ;
} void smain() {
while (cin >> n) {
if (n == )break;
mmm(f, ); mmm(dp, );
string c;
cin >> c;
int x = num(c[]);
if (x==-) {
//cout << ~x << endl;
dp[][][] = ;
ans = ;
}
else {
dp[x][][] = ;
dp[][x][] = ;
dp[][][x] = ;
ans = ;
}
rep(i, , n) {
string c;
cin >> c;
int x = num(c[]);
rep(j, , )rep(k, , )rep(l, , ) if(dp[j][k][l]){
int t = dp[j][k][l];
if ((x == - && j < ) || x + j == ) f[][k][l] = max(f[][k][l], t + );//放第一组//正好21,[j][k][l]->[0][k][l]
else if (x + j < )f[j + x][k][l] = max(f[x + j][k][l], t + );//没到21[j][k][l]->[x + j][k][l]
else if (x + j > && j < )f[][k][l] = max(f[][k][l], t + );//超了21[j][k][l]->[21][k][l] if ((x == - && k < ) || x + k == ) { f[j][][l] = max(f[j][][l], t + ); }
else if (x + k < )f[j][k+x][l] = max(f[j][k+x][l], t + );
else if (x + k > && k < )f[j][][l] = max(f[j][][l], t + ); if ((x == - && l < ) || x + l == ) { f[j][k][] = max(f[j][k][], t + ); }
else if (x + l < )f[j][k][l+x] = max(f[j][k][l+x], t + );
else if (x + l > && l < )f[j][k][] = max(f[j][k][], t + );
}
rep(j, , )rep(k, , )rep(l, , )dp[j][k][l] = f[j][k][l], ans = max(ans,dp[j][k][l]), f[j][k][l] = ;
}
cout << ans << endl;
} }

Deck of Cards ZOJ - 2852 dp 多决策 三维 滚动更新的更多相关文章

  1. Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)

    Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...

  2. Codeforces 745E Hongcow Buys a Deck of Cards 状压DP / 模拟退火

    题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理, ...

  3. 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 ...

  4. 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 ...

  5. [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 ...

  6. 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 ...

  7. 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 ...

  8. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  9. 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 ...

随机推荐

  1. Nginx 目录结构

    Nginx 目录结构 Nginx 安装后整体的目录结构及文件功能如下: [root@localhost ~]# tree /usr/local/nginx /usr/local/nginx ├── c ...

  2. unity中的透视投影矩阵

    一,unity中的Matrix4x4 例如一个矩阵的数据是: 0.9758,0,0,0,0,1.73205,0,0,0,0,-2.25,-16.25,0,0,-1,0 则实际矩阵是: M= m00 m ...

  3. CentOS 7 安装配置zabbix 3.2.8

    运行环境:CentOS 7.2 LNMP(已提前安装好此环境) 1.首先导入zabbix安装源# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x ...

  4. 模仿Semaphore自定义自己的 信号量

    简介 这里模仿Semaphore,自定义自己的信号量,利用AQS共享模式 1.MySemaphore.java package com.jacky; import java.util.concurre ...

  5. 两次内存断点法寻找OEP

    所谓“两次内存断点法寻找OEP”,按照<加密与解密*第三版>上的解释来说,就是这样的.一般的外壳会依次对.text..rdata..data..rsrc区块进行解压(解密)处理,所以,可以 ...

  6. 快播王欣发布匿名IM社交软件“马桶MT”

    2019年1月14日,快播王欣推出了一款匿名IM社交软件——马桶MT,它的灵感像是来自于美国的匿名分享应用Secret(已关闭). 原快播创始人王欣近日在微博预告了其新公司云歌人工智能推出一款全新社交 ...

  7. 性能优化系列八:MYSQL的配置优化

    一.关键配置 1. 配置文件的位置 MySQL配置文件 /etc/my.cnf 或者 /etc/my.cnf.d/server.cnf 几个关键的文件:.pid文件,记录了进程id.sock文件,是内 ...

  8. oracle函数详解-转

    1.SQL 语句基础 下面给出SQL语句的基本介绍. 1.1.SQL语句所用符号 操作符 用途 例子 + - 表示正数或负数,正数可省去 + -1234.56 + 将两个数或表达式进行相加 A=c+b ...

  9. Ubuntu上运行Blender,在控制台上查看运行结果

    1.首先在控制台打开Blender. 具体操作:找到Blender的安装路径,我的是:/home/lcx/下载/blender-2.78c-linux-glibc219-x86_64 $cd /hom ...

  10. 仿迅雷播放器教程 -- 基于ffmpeg的C++播放器 (1)

    2011年12月份的时候发了这篇博客 http://blog.csdn.net/qq316293804/article/details/7107049 ,博文最后说会开源一个播放器,没想到快两年了,才 ...