9.17京东笔试
1.交换下直接算即可
2.贪心找最大
3.第三题,dp写的一点问题没有不知道为啥百分之7,妈的一个个测数据一点没问题,数据不知道怎么就百分之7
public class third {
static int mod = (int)1e9+7;
static long[][][]dp;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long l = System.currentTimeMillis();
int po = 'e'-'a',ptw = 'd'-'a';
dp = new long[n][26][26];
long res = 0;
for (int i = 0; i <= n-3; i++) {
res = (res+dfs(i,po,ptw)*dfs(n-i-3,po,ptw))%mod;
}
System.out.println(res);
System.out.println(System.currentTimeMillis()-l);
}
private static long dfs(int n,int po, int ptw) {
if(n<=0)
return 1;
if(dp[n][po][ptw]!=0)
return dp[n][po][ptw];
long res = 0;
if(po=='d'-'a'&&ptw=='e'-'a'){
res = dfs(n-1,ptw,0)*23%mod;
} else {
res = dfs(n - 1, ptw, 0) * 24 % mod;
}
res = (dfs(n - 1, ptw, 'e' - 'a') + res) % mod;
res = (dfs(n - 1, ptw, 'd' - 'a') + res) % mod;
dp[n][po][ptw] = res;
return res;
}
}