文章标题
来源:互联网 发布:如何开通淘宝客 编辑:程序博客网 时间:2024/05/29 18:51
阿利亚正在解一道数学题,给出了一颗有N个节点的树,索引从1到N,具体见下:
static int find(int numNodes, int rootNode, int[] values, int[][] edges) { int max = Integer.MIN_VALUE; int temMax = 1; for (int i = 0; i < edges.length; i++) { // 找到第1组 temMax = 1; if (edges[i][0] == 1) {//改为==rootNode 当第i个为1才开始 temMax = values[ edges[i][0]-1 ] * values[edges[i][1]-1]; int t = edges[i][1]; int j = i + 1; while (j < edges.length) { if (edges[j][0] == t) {// 连起来了 temMax = temMax * values[ edges[j][1]-1 ]; t = edges[j][1]; } j++; } } max = Math.max(max, temMax); } return max; } public static void main(String[] args) { int[] values = {2,4,10,20,1}; int[][] edges={{1,2},{1,3},{2,4},{2,5}}; int res=find(0, 0, values, edges); System.out.println(res); } //答案160
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 【Unity游戏开发】浅谈Unity游戏开发中的单元测试
- HDU 5738 Eureka (共线点集 组合数)
- 51nod 1001 数组中和等于K的数对
- Java 中Timer和TimerTask 定时器和定时任务使用的例子
- jQuery选择器总结
- 文章标题
- c++指针中0,NULL和nullptr
- A Boring Question HDU
- ThreadLocal
- H.264中I帧和IDR帧的区别
- PAT乙级1048. 数字加密(20)
- 2017第34届广州国际特许连锁加盟展览会会刊(参展商名录)
- MySQL插入表之后中文显示乱码(个人总结篇)
- ubtun系统默认是没有激活root用户