Help Captain Chen Ⅰ

来源:互联网 发布:java开根号 编辑:程序博客网 时间:2024/05/20 02:54

Description

Recently, more and more students pay attention to a funny game called ACM, including Captain Chen. He finds that to compete in the Finals he must get a good rank in the Regionals and that to compete in the Regionals he must join BUPT ACM training team firstly. This is not easy because FJ has already announced that anyone who has not solved at least 300 problems is forbidden to join the training team. 
Usually it’s hard to solve a problem because there are a lot of skills and characteristics required, including some specific algorithms, coding ability, cautions, etc. So, although there are a lot of problems on the OJ, only few of them can be solved by him. But fortunately, once he has successfully AC a problem, he get a progress, while a second AC of the same problem won’t benefit him anymore. Now he is afraid of not being able to join the training team. Can you help him?
For simplicity, assume there are N problems on the OJ and there are M kinds of skills it may need to solve a problem. And the level of a skill can be represented as an integer. The bigger the integer is, the greater the ability to the skill Captain Chen has.
  
Input
The first line of the input contains a single integer T, indicating there are T cases.
In each case, the first line contains two integers N and M, which are described above. The second line contains M integers, indicating the initial level of each skill of Captain Chen. Next there are M lines each containing N integers. The jth integer in the ith line indicates the level of the ith skill required to solve the jth problem. And next there are again M lines each containing N integers. The jth integer in the ith line indicates the level of improvement of the ith skill Captain Chen can get if he AC the jth problem(For example, if his level of ith skill is 3, and he gets an improvement of 2, then his level of ith skill is increased to 5).
We guarantee that all the integers above are non-negative, and are no more than 1000,000,000. And you can assume that 0<N*M<=100,000.
The input file is as large as about 20MB. So please use “scanf” instead of “cin” while using c++.
   
Output
The output of each case contains a single integer, the maximum problems Captain Chen can solve. 

Sample Input
2
3 2
1 0
1 2 1
0 0 2
1 0 1
0 1 2
4 3
0 1 1
2 0 1 4
2 0 0 2
2 1 3 0
1 6 2 0
0 1 1 0
0 2 1 2

Sample Output
2
4


#include<stdio.h>#include<malloc.h>//int a[2000][2000],b[2000][2000];//int skill[2000];//int flag[20000]={0};//int solved[20000]={0};int main(){int t;int i,j,k;int n,m;i=0;scanf("%d",&t);while(i<t){scanf("%d %d",&n,&m);//n个问题,m个技能///动态申请int ** a=(int **)malloc((m+2)*sizeof(int *));for(j=1;j<=m;j++){a[j]=(int *)malloc((n+2)*sizeof(int));}int ** b=(int **)malloc((m+2)*sizeof(int *));for(j=1;j<=m;j++){b[j]=(int *)malloc((n+2)*sizeof(int));}int * skill=(int *)malloc((m+2)*sizeof(int));int * solved=(int *)malloc((n+2)*sizeof(int));////for(j=1;j<=m;j++)scanf("%d",&skill[j]);for(j=1;j<=n;j++){solved[j]=0;}for(j=1;j<=m;j++){for(k=1;k<=n;k++){scanf("%d",&a[j][k]);}}for(j=1;j<=m;j++){for(k=1;k<=n;k++){scanf("%d",&b[j][k]);}}int sum=0;for(j=1;j<=n;j++){if(solved[j])continue;int ok=1;for(k=1;k<=m;k++){if(skill[k]<a[k][j]){ok=0;break;}}if(!ok)continue;else{for(k=1;k<=m;k++){skill[k]+=b[k][j];}solved[j]=1;sum++;j=0;}}printf("%d\n",sum);i++;}return 0;}