编程介的小学生 2019-02-03 16:12 采纳率: 20.5%
浏览 533

矩阵求和变量取最大输出,这个问题采用C语言的解决的思路

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

  • 写回答

1条回答 默认 最新

  • deng展hua 2019-02-07 21:06
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题