原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2614
一:原题内容
3 0 0 0 1 0 1 1 0 0 3 0 2 2 1 0 1 1 1 0 5 0 1 2 3 1 0 0 2 3 1 0 0 0 3 1 0 0 0 0 2 0 0 0 0 0
3 2 4HintHint: sample one, as we know zty always solve problem 0 by costing 0 minute. So after solving problem 0, he can choose problem 1 and problem 2, because T01 >=0 and T02>=0. But if zty chooses to solve problem 1, he can not solve problem 2, because T12 < T01. So zty can choose solve the problem 2 second, than solve the problem 1.
二:理解分析
一个人做n道题,但是他有一个习惯,每做一题,该题必须比上一次做的题的难度大,难度大小根据做题所需的时间判断。
三:AC代码
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 #include<iostream> #include<string.h> #define max(a, b) (((a) > (b)) ? (a) : (b)) using namespace std; bool visit[16]; //从0到n-1标记题号是否做过 int time[16][16]; // int n; // int sum; //记录做出题的最大数 void DFS(int, int, int); int main() { while (cin >> n) { memset(visit, 0, sizeof(visit)); sum = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> time[i][j]; DFS(0, 0, 1);//第二个参数只要不大于0就行,也就是小于等于0皆可 visit[0] = 1;//解决第一题 cout << sum << endl; } return 0; } void DFS(int cur,int lastTime,int cnt)//cur代表现在正要解决的题号(从0到n-1),也就是time数组的横坐标;lastTime是上一次做题的时间;cnt是已经解决了多少题 { sum = max(sum, cnt);//这里要随时更新,因为题意是找到所能做出的题目的最大值 if (sum == n)//如果能把所有题目做完,那还做什么呢?停止! return; for (int i = 1; i < n; i++)//第一题已被解决,所以从1开始 { if (!visit[i] && time[cur][i] >= lastTime) { visit[i] = 1; DFS(i, time[cur][i], cnt+1); visit[i] = 0; } } }