NOIP 2015 Day T3 landlords 斗地主

来源:互联网 发布:淘宝开店必备条件 编辑:程序博客网 时间:2024/05/21 02:50

当时考试的时候没调出来, 悲催的只有30分;

其实就是贪心+Dfs;

优先考虑各种顺子,然后考虑带牌, 最后对子和单牌;

注意带牌 带对子不能是双王;

下面我把牌值换了一下:

原来是 3 4 5 6 7 8 9 10 J Q K   A   2  小王 大王

代码中 0 1 2 3 4 5 6 7   8 9 10 11 12 13   14

#include<cstdio>#include<cstring>#include<iostream>using namespace std;int n, ans, p[15], L[4];inline int read() {int ret = 0, k = 1; char ch = getchar();while(ch < '0' || ch > '9') { if(ch == '-') k = -1; ch = getchar(); }while(ch >='0' && ch <= '9') {ret *= 10; ret += ch - '0'; ch = getchar(); }return ret * k;}void Dfs(int dep, int k) {if(!k) { ans = min(ans, dep); return ; }if(dep >= ans) return ;for(int i = 0; i < 13; i++) if(p[i] == 3) { // 三带几 p[i] -= 3; Dfs(dep+1, k-3); // 独三 for(int j = 0; j < 15; j++) if(p[j] && j!=i) { // 三带一 p[j]--; Dfs(dep+1, k-4); if(p[j]) { p[j]--; Dfs(dep+1, k-5); p[j]++; } // 三带二 p[j]++;} p[i] += 3;}for(int i = 0; i < 13; i++) if(p[i] == 4) { //  四带几 p[i] -= 4; Dfs(dep+1, k-4); // 炸弹 for(int j = 0; j < 13; j++) if(p[j]) { // 四带二 p[j]--;for(int t = j; t < 13; t++) if(p[t]) { p[t]--; Dfs(dep+1, k-6); p[t]++; } p[j]++;}for(int j = 0; j < 13; j++) if(p[j]>1) { // 四带二对 p[j] -= 2;for(int t = j; t < 13; t++) if(p[t]>1) { p[t] -= 2; Dfs(dep+1, k-8); p[t] += 2; } p[j] += 2;} p[i] += 4;}for(int i = 0; i < 13; i++) { dep += (p[i]/2) + (p[i]%2); if(dep >= ans) return ; } //单牌 对子 if(p[13] == 1 || p[14] == 1) dep++; ans = min(ans, dep); // 双王 }void Solve(int dep, int k) {    if(!k) { ans = min(ans, dep); return ; }if(dep >= ans) return ;for(int t = 1; t <= 3; t++) // 顺子 for(int i = 0; i < 13-L[t]; i++) if(p[i] >= t) { int len = 1, j; for(j = i+1; j < 12; j++) if(p[j] < t) break; else len++; if(len < L[t]) { i = j; continue; } for(j = i; j < i+len; j++) p[j] -= t;for(j = len; j >= L[t]; j--) { Solve(dep+1,k-t*j); p[i+j-1] += t; }for(j = i; j < i+L[t]-1; j++) p[j] += t;}Dfs(dep, k);}int main() {int T = read(); n = read(); L[1] = 5; L[2] = 3; L[3] = 2;while(T--) {memset(p, 0, sizeof(p));for(int i = 1; i <= n; i++) {int c = read(), c2 = read();if(c > 2) c -= 3; else if(!c) c = 12+c2; else c += 10;p[c]++;} ans = n; Solve(0, n); printf("%d\n", ans); }return 0;}


0 0
原创粉丝点击