HDU:2614 beat

来源:互联网 发布:淘宝七星彩摇奖机 编辑:程序博客网 时间:2024/06/05 05:44

Beat

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1446    Accepted Submission(s): 849

Problem Description
Zty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solve
a problem that is 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. 
You may sure zty first solve the problem 0 by costing 0 minute. Zty always choose cost more or equal time’s problem to solve.
 
Input
The input contains multiple test cases.
Each test case include, first one integer n ( 2< n < 15).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 solving the problem i, will cost Tij minute to solve the problem j.

 
Output
For each test case output the maximum number of problem zty can solved.
Tjk>Tij
 
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
324
Hint
Hint: 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.

题目意思,I行J列的Tij代表解决完I问题后,会花费Tij时间去解决J问题,而且问题的难度一定前一个大。
如果现在解决了Tij也就是第I行,J列的一个问题,则他要处理的下一个问题,是在第J行的某一列找的。也就是这些处理的问题都是
不同行的。
也就是T[i][j]<=T[j][k]条件成立时,我就处理T[j][k]问题。


题目代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#define max(a,b) a>b?a:b
#define INF 0x3f3f3f3f
using namespace std;
int Map[20][20],vis[20]; //vis用来记录该行有没有用过
int mmax,N;
void dfs(int now,int num,int per) //now是当前搜索的行坐标
{
    mmax=max(num,mmax); //mmax为当前做的题目数量与最大值两者中的最大值
    if(now==N) //如果搜索到了第N行,说明此次搜索完毕,返回
        return;
    for(int i=1;i<N;i++)
    {
        if(vis[i]) //这一行已经选出一个了
            continue; //跳过本次循环
        if(Map[now][i]>=per)//下一道的难度要比上一道的难
        {
            vis[i]=1;
            dfs(i,num+1,Map[now][i]); //I为列序,为下次要搜索的行序
            vis[i]=0;
        }
    }
}
int main()
{
    int i,j;
    while(~scanf("%d",&N))
    {
        for(i=0;i<N;i++)
            for(j=0;j<N;j++)
            scanf("%d",&Map[i][j]);
        mmax=-INF; //将最大值初始化为负无穷
        memset(vis,0,sizeof(vis)); //将vis初始化为0
        vis[0]=1; //题目说了,第一行要取第一个难度为0的,所以第一行一定会做第一个问题,直接标记为1,
        for(i=1;i<N;i++) //对下面N-1行进行搜索
        {
            vis[i]=1; //当前行变成1,因为这个数组中的数都大于等于0,所以必存在一个值符合条件,
            dfs(i,2,Map[0][i]); //而且第一个就符合条件,所以最初题目个数为2个。
            vis[i]=0;
        }
        printf("%d\n",mmax);
    }
    return 0;
}
0 0
原创粉丝点击