Problem Description
Let A be a 1*N matrix, and each element of A is either 0 or 1. You are to find such A that maximize D=(A*B-C)*AT, where B is a given N*N matrix whose elements are non-negative, C is a given 1*N matrix whose elements are also non-negative, and AT is the transposition of A (i.e. a N*1 matrix).
Input
The first line contains the number of test cases T, followed by T test cases.
For each case, the first line contains an integer N (1<=N<=1000).
The next N lines, each of which contains N integers, illustrating the matrix B. The jth integer on the ith line is B[i][j].
Then one line followed, containing N integers, describing the matrix C, the ith one for C[i].
You may assume that sum{B[i][j]} < 2^31, and sum{C[i]} < 2^31.
Output
For each case, output the the maximum D you may get.
Sample Input
1
3
1 2 1
3 1 0
1 2 3
2 3 7
Sample Output
2
#include
#define N 80
int input(int *arr)
{ int *pnew=arr; int count=0;
printf("请输入整型数据(按q/Q退出:)\n");
while(1==scanf("%d",pnew)&&pnew<arr+N-1) { count++; pnew++; }
printf("输入数据完毕!\n"); return count;}void show(int *arr,int n){ int *p; for(p=arr;p<arr+n;p++) printf("%d ",*p); printf("\n"); return;}long sum(int *arr,int n){ long s=0; int *p=arr; while (p<arr+n) { s+=*p++; } return s;}int max(int *arr,int n){ int m=*arr; int *p; for(p=arr;p<arr+n;p++) { if (m<*p) m=*p; } return m;} int main(void){ int a[N],n; n=input(a); show(a,n); printf("数组元素之和是%ld\n",sum(a,n)); printf("最大元素值是%d\n",max(a,n)); return 0;}