【DP】ZOJ 2852 Deck of Cards
来源:互联网 发布:node.js 手机 编辑:程序博客网 时间:2024/06/06 01:43
ZOJ 2852 Deck of Cards
参考自:AC_Von
f[j][k][l]表示slot x1, x2, x3的值为j,k,l时的最优值。pre[j][k][l]表示他的前一个状态。
#include <iostream>#include <algorithm>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <cmath>using namespace std;int f[30][30][30], p[30][30][30];int char2num(char c){ if(c>='2' && c<='9') return c-'0'; if(c == 'A') return 1; if(c == 'F') return -1; return 10;}int main(int argc, char const *argv[]){ // freopen("in", "r", stdin); int n; while(scanf("%d", &n), n){ memset(f, 0, sizeof(f)); memset(p, 0, sizeof(p)); char str[2]; int ans = 0, t, tt; scanf("%s", str); t = char2num(str[0]); if(t == -1){ p[0][0][0] = 350; ans = 350; }else{ p[t][0][0] = 50; p[0][t][0] = 50; p[0][0][t] = 50; ans = 0; } for(int i = 0; i < n-1; i++){ scanf("%s", str); t = char2num(str[0]); for(int j=0; j<22; j++){ for(int k=0; k<22; k++){ for(int l=0; l<22; l++){ if((tt = p[j][k][l]) == 0) continue; //1x if((t == -1 && j < 21) || t + j == 21) { f[0][k][l] = max(f[0][k][l], tt + 150); } else if(t + j < 21) { f[j+t][k][l] = max(f[t+j][k][l], tt + 50); } else if(t + j > 21 && j < 21) { f[21][k][l] = max(f[21][k][l], tt + 50); } //2x if((t == -1 && k < 21) || t + k == 21) { f[j][0][l] = max(f[j][0][l], tt + 250); } else if(t + k < 21) { f[j][t+k][l] = max(f[j][t+k][l], tt + 50); } else if(t + k > 21 && k < 21) { f[j][21][l] = max(f[j][21][l], tt + 50); } //3x if((t == -1 && l < 21) || t + l == 21) { f[j][k][0] = max(f[j][k][0], tt + 350); } else if(t + l < 21) { f[j][k][l+t] = max(f[j][k][l+t], tt + 50); } else if(t + l > 21 && l < 21) { f[j][k][21] = max(f[j][k][21], tt + 50); } } } } for(int j=0; j<22; j++){ for(int k=0; k<22; k++){ for(int l=0; l<22; l++){ p[j][k][l] = f[j][k][l]; ans = max(ans, p[j][k][l]); f[j][k][l] = 0; } } } } printf("%d\n", ans); } return 0;}
0 0
- ZOJ 2852 Deck of Cards(DP)
- 【DP】ZOJ 2852 Deck of Cards
- ZOJ 2852Deck of Cards(DP)
- ZOJ 2852 Deck of Cards
- zoj 2852 Deck of Cards扑克牌(三维dp)
- D2: deck of cards
- shuffle a deck of cards
- Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards(DP/模拟退火)
- Codeforces Round #385 (Div. 2) E. Hongcow Buys a Deck of Cards DP+好题
- zoj 1216 Deck
- ZOJ 1216 Deck
- zoj 1216 Deck
- ZOJ 1216 Deck
- ZOJ Problem Set - 1216 Deck
- ZOJ 3380 Patchouli's Spell Cards(DP,大数)
- ZOJ 3380 Patchouli's Spell Cards (概率dp)
- ZOJ 3380 Patchouli's Spell Cards 概率DP
- Zoj 3380 Patchouli's Spell Cards (概率dp)
- 例题6-4 破损的键盘 UVa11988
- 黑马程序员——String(常见功能)
- [leetcode]Subsets II
- IIS 访问 SQL Server
- android studio启动一直卡在fetching Android sdk compoment的解决方案
- 【DP】ZOJ 2852 Deck of Cards
- ViewPager与DrawerLayout以及百度MapView之间滑动冲突的解决
- 计算二叉树先序中序后序
- 状态模式与职责链模式
- MapReduce学习笔记
- For And While
- 设计模式(一)之策略模式
- Android设置logcat的System.out过滤不起作用的解决
- 菜鸟我眼中的IPM++