zoukankan      html  css  js  c++  java
  • I

    Beat

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

    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.
    Sample Input
    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
     
    Sample Output
     
    3 2 4
     
    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.

    题意:

     一个小孩要做n道题,且这n道题难度不同。mp[i][j]代表做完第i道题后,再做第j道题的难度系数,每次做题难度系数不断上升,问最多做题数。

    思路:

      简单DFS,具体看代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #define INF 0x3f3f3f3f
     5 #define N 20
     6 using namespace std;
     7 int vis[N];//标记
     8 int mp[N][N];
     9 int n;
    10 int ans;
    11 void DFS(int s,int len,int num){//s--下一道题,len--做题的数量,num--记录上一题的难度系数  
    12 int flag=0;
    13 for(int j=0;j<n;j++){
    14     if(!vis[j]&&s!=j&&mp[s][j]>=num){//如果没有标记并且难度系数上升
    15         vis[j]=1;
    16         DFS(j,len+1,mp[s][j]);
    17         vis[j]=0;
    18         flag=1;
    19     }
    20 }
    21 if(!flag)ans=max(ans,len);
    22 }
    23 
    24 int main(){
    25 while(~scanf("%d",&n)){
    26     ans=-1;
    27     memset(vis,0,sizeof(vis));
    28     for(int i=0;i<n;i++){
    29         for(int j=0;j<n;j++)
    30             scanf("%d",&mp[i][j]);
    31     }
    32     vis[0]=1;
    33     DFS(0,1,0);
    34     printf("%d
    ",ans);
    35 }
    36 return 0;
    37 }
    View Code
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    椭圆形 上传图片预览 image preview (未整理版本)
    canvas学习笔记03:简单脉冲效果
    canvas学习笔记02:饼图&柱状图
    canvas学习笔记01:Math.sin & Math.cos
    java jdk 随机数阻塞问题
    家政/保洁 平台设计
    Lock和synchronized
    jvm 中java new 对象顺序
    Java 多线程原理
    java ftp上传下载,下载文件编码设置
  • 原文地址:https://www.cnblogs.com/by-DSL/p/8654660.html
Copyright © 2011-2022 走看看