第一题:235
第二题:滚球
import java.util.Scanner; public class Main { public static int num(int n){ int[] res = new int[n]; res[0] = 2; res[1] = 3; res[2] = 5; for (int i = 3; i < n; i++) { if(i % 3 == 0){ res[i] = res[i / 3 - 1] * 10 + 2; }else if(i % 3 == 1){ res[i] = res[i / 3 - 1] * 10 + 3; }else { res[i] = res[i / 3 - 1] * 10 + 5; } } return res[n - 1]; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(num(sc.nextInt())); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] arr = new int[n][2 * n - 1]; int[][] index = new int[n][2 * n - 1]; for (int i = 0; i < n; i++) { for (int j = (2 * n - 1) / 2 - i; j <= (2 * n - 1) / 2 + i; j++) { arr[i][j] = sc.nextInt(); } } for (int i = 0; i < arr[0].length; i++) { index[0][i] = arr[0][i]; } for (int i = 1; i < n; i++) { for (int j = (2 * n - 1) / 2 - i; j <= (2 * n - 1) / 2 + i; j++) { if(j - 1 >= 0 && j + 1 < arr[0].length){ index[i][j] = Math.max(index[i - 1][j - 1], Math.max(index[i - 1][j], index[i - 1][j + 1])) + arr[i][j]; } if(j - 1 == -1){ index[i][j] = Math.max(index[i - 1][j], index[i - 1][j + 1]) + arr[i][j]; } if(j + 1 == arr[0].length){ index[i][j] = Math.max(index[i - 1][j - 1], index[i - 1][j]) + arr[i][j]; } } } int max = 0; for (int i = 0; i < arr[0].length; i++) { max = Math.max(max, index[n - 1][i]); } System.out.println( max); } }
全部评论
(0) 回帖