1.题目描述:点击打开链接
2.解题思路:本题虽然是动态规划专题的习题,但更像是一道用回溯法解决的问题。定义d(a,b,c,d)表示分别从每堆拿走a,b,c,d个糖果时的最大配对数目。每次都枚举从四个糖果堆拿糖的情况,并用hash数组来判断篮子中糖果的奇偶性。刚刚有一个时是false变为true,恰好配对是true变为false。
3.代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;
#define maxn 45
int pile[4][maxn];
int d[maxn][maxn][maxn][maxn];//表示分别从每堆中拿a,b,c,d个时,最多能拿多少对糖果
int num[4];
int h;
int dp(int count, bool hash[])//count记录