HDU1176

来源:互联网 发布:mac专柜价多少 编辑:程序博客网 时间:2024/05/24 01:07

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176

 

package DP;import java.util.*;public class HDU1176 {// arr[i][j]表示第i秒第j个位置的馅饼的数目。static int[][] arr;public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n;while (sc.hasNext()) {arr = new int[100001][11];n = sc.nextInt();if (n == 0)break;int maxt = 0;// 最大时间。while (n-- > 0) {int x = sc.nextInt();int t = sc.nextInt();arr[t][x]++;if (t > maxt)maxt = t;}for (int i = maxt - 1; i >= 0; i--) {for (int j = 1; j <= 9; j++) {arr[i][j] += getMax(arr[i + 1][j - 1], arr[i + 1][j], arr[i + 1][j + 1]);}arr[i][0] += Math.max(arr[i + 1][0], arr[i + 1][1]);arr[i][10] += Math.max(arr[i + 1][10], arr[i + 1][9]);}System.out.println(arr[0][5]);}}private static int getMax(int a, int b, int c) {int max1;max1 = a > b ? a : b;max1 = max1 > c ? max1 : c;return max1;}}


 

原创粉丝点击