解决方案 »

  1.   

    这个采药就是01背包问题,我改成这样,还是超时 import java.util.Scanner;public class Main {
        public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()) {    
            int timTotal = scanner.nextInt();
            int hrbTotal = scanner.nextInt();
            int[][] values = new int[hrbTotal + 1][timTotal + 1];
            int lastHerb = hrbTotal;
            int lastTime = timTotal;        int tmpValue1 = 0;
            int tmpValue2 = 0;
            int[] time = new int[hrbTotal + 1];
            int[] value = new int[hrbTotal + 1];
            time[0] = 0;
            value[0] = 0;
            int count = 1;        while (count <= hrbTotal) {
                time[count] = scanner.nextInt();
                value[count] = scanner.nextInt();
                count++;
            }
            for (int i = 1; i <= lastHerb; i++)
                for (int j= 1; j <= lastTime; j++) { 
                    if (i == 1)
                        values[0][j] = 0;
                    tmpValue1 = values[i-1][j];
                    if (j >= time[i])
                        tmpValue2 = values[i-1][j-time[i]] + value[i];
                    else
                        tmpValue2 = 0;
                    values[i][j] = tmpValue1>=tmpValue2?tmpValue1:tmpValue2;
                }
            
            System.out.println(values[lastHerb][lastTime]);    }
        }
    }只是改了几个名字。不知道哪里可以继续优化,还是什么其他问题。。
      

  2.   

    目前英雄会的OJ模式有问题,Java和C#的代码测试时永远读不到输入,然后就超时了,节哀
      

  3.   

    这位仁兄,这个消息你是从哪里得到的?官方的,还是自己测试过总结出来的?你把代码逻辑全部删掉,只留一句读取输入,你就会发现结果依然是超时,我向管理员反映过,已确认Java和C#存在这个问题
      

  4.   

    http://bbs.csdn.net/topics/390724211?page=1
      

  5.   

    这位仁兄,这个消息你是从哪里得到的?官方的,还是自己测试过总结出来的?你把代码逻辑全部删掉,只留一句读取输入,你就会发现结果依然是超时,我向管理员反映过,已确认Java和C#存在这个问题
    我试了一下,确实是如此