官方提供的,输入以下: 5 5 0 0 0 0 0 0 0 0 0 1 876 1 566 920 598 259 945 123 659 997 176 478 293 464 278
得到的正确答案为:118214
而我用自己的代码算出来的却是:116126 实在找不出那里错了(先排除用高精)
import java.util.Arrays;
import java.util.Scanner;
public class P1005 {
public static int n,m;
public static int[][] arr;
public static boolean[][] f;
//返回列
public static int fun(int i) {
int min = 0;
int l=0,r=m-1;
while (true) {
if (f[i][l]==false && f[i][r]==false) {
break;
}
if (f[i][l]==true) {
l++;
}
if (f[i][r]==true) {
r--;
}
}
return arr[i][l]<arr[i][r]?l:r;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
m = scan.nextInt();
long sum = 0;
arr = new int[n][m];
f = new boolean[n][m];
for (int i=0;i<n;i++) {
for (int j=0;j<m;j++) {
arr[i][j] = scan.nextInt();
}
}
for (int j=1;j<=m;j++) { //取的次数
for (int i=0;i<n;i++) { //第i行
int k = fun(i);
f[i][k] = true;
sum += (long)arr[i][k]*(long)((int)Math.pow(2, j));
}
}
System.out.println(sum);
}
}