BeatTime
limit:6000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 669 Accepted Submission (s): 424
Problem Descriptionzty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he have a habit that he does not like to solve
A problem that's easy than problem he had solved. Now Yifenfei give him n difficulty problems, and tell him their relative time to solve it after solving the other one.
You should help Zty to find a order of solving problems to solve more difficulty problem.
Sure Zty first solve the problem 0 by costing 0 minute. Zty always choose cost more or equal time's problem to solve.
Inputthe input contains multiple test cases.
Each test case include, first one integer n (2< n <). Express the number of problem.
Than n lines, each line include n integer Tij (0<=tij<10), the I ' s row and J's Col integer Tij Express after Solvin G The problem I, would cost Tij minute to solve the problem J.
Outputfor each test case output the maximum number of problem zty can solved.
Sample Input
30 0 01 0 11 0 030 2 21 0 11 1 050 1 2 3 10 0 2 3 10 0 0 3 10 0 0 0 20 0 0 0 0
Sample Output
324Hinthint: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.
#include <stdio.h>const int N = 1<<14;const int inf = 0xffffff;int k[n];void init () {for (int i=1;i<n; i++ ) {int n=0; for (int s=0; (1<<s) <=i; s++) if ((1<<s) &i) n++; K[i]=n; }}int Main () {int n,map[14][14],dp[n][14],maxlen; Init (); while (scanf ("%d", &n) >0) {for (Int. i=0;i<n;i++) for (int j=0;j<n;j++) scanf ("%d ", &map[i][j]); for (int s=1;s< (1<<n), s++) for (int i=0;i<n;i++) Dp[s][i]=inf; dp[1<<0][0]=0; maxlen=0; for (int s=1; s< (1<<n); s++) for (int i=0; (1<<i) <=s; i++) if (dp[s][i]!=inf) {if (Maxlen<k[s]) maxlen=k[s]; for (int j=0;j<n;j++) if (! ( (1<<j) &s) &&map[i][j]>=dp[s][i]&&dp[s| ( 1<<J)][j]>map[i][j]) dp[s| ( 1<<J)][j]=map[i][j]; } printf ("%d\n", maxlen); }}
Hdu2614beat (DP State compression path)