出现了一点问题,题目不能复制过来,主要的大意是有4堆糖果,有一个篮子,这个篮子最多可以装5个糖果,从4堆糖果堆的顶部每次取一个糖果,如果篮子中有颜色相同的一对糖果那么就可以装进口袋里,否则口袋达到5个后就结束游戏。
https://vjudge.net/problem/UVA-10118
上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#define max(a,b) (((a)>(b))?(a):(b))
using namespace std;
const int maxn = 42;
int n;
int G[maxn][4];
int top[4];
int dp[maxn][maxn][maxn][maxn];
int match[22];
int dfs (int length , int *match) {
if (dp[top[0]][top[1]][top[2]][top[3]] != -1)
return dp[top[0]][top[1]][top[2]][top[3]];
if (length == 5)
return dp[top[0]][top[1]][top[2]][top[3]] = 0;
int ans = 0;
for (int i = 0 ; i < 4 ; i++) {
if (top[i] >= n)
continue;
int tc = G[top[i]][i];
top[i]++;
if(!match[tc]) {
match[tc] = 1;