http://poj.org/problem?id=2442
题解http://www.cnblogs.com/372465774y/archive/2012/07/09/2583866.html
本来写的二维数组 ,直接対一维排序 不知道为嘛一直WA 只好该为一维的 就AC了
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 int num1[2005],num2[2005]; 8 bool cmp(int a,int b) 9 { 10 return a<b; 11 } 12 int main() 13 { 14 int i,j,k,n,m,t; 15 cin>>t; 16 while(t--) 17 { 18 priority_queue <int> q; 19 cin>>n>>m; 20 for(i = 1; i <= m ; i++) 21 cin>>num1[i]; 22 sort(num1+1,num1+m+1); 23 for(i = 1 ; i < n; i++) 24 { 25 for(k = 1; k <= m ; k++) 26 { 27 cin>>num2[k]; 28 q.push(num1[1]+num2[k]); 29 } 30 sort(num2+1,num2+m+1,cmp); 31 for(k = 2; k <= m ; k++) 32 for(j = 1; j <= m ; j++) 33 { 34 if(num1[k]+num2[j]>q.top()) 35 break; 36 q.pop(); 37 q.push(num1[k]+num2[j]); 38 } 39 for(k = m; k >= 1 ; k--) 40 { 41 num1[k] = q.top(); 42 q.pop(); 43 } 44 } 45 for(i = 1; i < m ;i++) 46 cout<<num1[i]<<" "; 47 cout<<num1[m]<<endl; 48 } 49 return 0; 50 }