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;
    }
}


#京东笔试#
全部评论
手撕代码吗
点赞 回复 分享
发布于 2022-09-18 18:52 陕西

相关推荐

评论
2
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务