360b卷编程题第一题(动态规划解法)

 
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] arg) {
        Scanner scanner = new Scanner(System.in); int inp = scanner.nextInt();
        String nu = scanner.nextLine();
        String str = scanner.nextLine();
        String[] strs = str.split(" ");
        List<Integer> lists = new ArrayList<>(); for (int i = 0; i < strs.length; i++) {
            lists.add(i, Integer.parseInt(strs[i]));
        }
        System.out.println(test(lists));
    } public static float test(List<Integer> str) { float count = 0; float t = 0; for (int j = 0; j < str.size(); j++) { if (str.get(j) == 2){
                str.set(j,1); float t1 = test(str);
                str.set(j,2);
                str.set(j,0); float t2 = test(str);
                str.set(j,2);
                count = (t1+t2)/2; return count;
            } if (str.get(j) == 1) {
                t = t + 1;
                count = count + t;
            } if (str.get(j) ==0){
                t=0;
                count =count +0;
            }
        } return count;
    }
}
#360笔试##笔试题目##360公司#
全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
评论
点赞
3
分享

创作者周榜

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