(我成功过了洛谷的加强版)
这道题肯定是不能直接贪心的,感觉状压也不是很好,最好的还是搜索。
(NOIP居然考了搜索。。。)
这道题的搜索只需要调整一下顺序即可。
我打了6层搜索,从上往下依次是四带二,三顺子,二顺子,顺子,三带二或者三带一,大王和小王,剩下的牌。
其中四带二,三带二和三带一不在搜索的时候处理带了那一张牌,放在最后贪心处理即可。
因为大王小王不能放在一对,所以要多打一重搜索判断一下。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n, a[21], ans;
void dfs1(int dep, int x, int y) {
if (dep >= ans) return;
int s1 = 0, s2 = 0;
for (int i = 2; i <= 14; i++) {
if (a[i] == 1) s1++;
else if (a[i] == 2) s2++;
else if (a[i] == 3) s1++, s2++;
else if (a[i] == 4) s2 += 2;
}
s1 += a[15];
int t; t = s1 / 2;
if (y >= t) y -= t, s1 -= 2 * t;
else s1 -= 2 * y, y = 0;
t = s2 / 2;
if (y >= t) s2 -= t * 2, y -= t;
else s2 -= 2 * y, y = 0;