第一题:玩具
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int N = (int)1e6 + 10;
static long[] a = new long[N];
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for(int i = 1; i <= n; i++) a[i] = s.nextInt();
long res = 0;
Arrays.sort(a, 1, n+1);
for(int i = n; i >= 1; i -= 2) {
res += a[i];
}
System.out.println(res);
}
}
第二题:滑雪
import java.util.Scanner;
public class Main {
static int N = 310;
static int[][] g = new int[N][N];
static int[][] dp = new int[N][N];
static int[] dx = {0, 1, 0, -1};
static int[] dy = {1, 0, -1, 0};
static int n, m;
static int dfs(int x, int y) {
if(dp[x][y] != 0) return dp[x][y];
dp[x][y] = 1;
for(int i = 0; i < 4; i++) {
int tX = x + dx[i], tY = y + dy[i];
if(tX >= 1 && tX <= n && tY >= 1 && tY <= m) {
if(g[tX][tY] < g[x][y])
dp[x][y] = Math.max(dp[x][y], dfs(tX, tY)+1);
}
}
return dp[x][y];
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
n = s.nextInt();
m = s.nextInt();
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
g[i][j] = s.nextInt();
}
}
int res = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
res = Math.max(res, dfs(i, j));
}
}
System.out.println(res);
}
}
第三题:aab
补题--------------------------------------------------
第四题:小红取数
补题----------------------------------------------------