Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

重做有感

Posted by 5D6D2 at 2012-09-14 18:22:34 on Problem 2442
In Reply To:有一位同学做出了此题的DP解! Posted by:yc5_yc at 2012-09-14 17:23:53
重做中……
2A
思路清晰了几倍,重做真好!

#include <cstdio>
#include <algorithm>
using namespace std;
const int NMax=2100;
int N,M,A[NMax][NMax];
int S1[NMax],S2[NMax],Heap[NMax];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--) {
        scanf("%d%d",&N,&M);
        for(int i=1;i<=N;i++)
            for(int j=1;j<=M;j++)
                scanf("%d",&A[i][j]);
        for(int i=1;i<=M;i++) S1[i]=A[1][i];
        sort(S1+1,S1+M+1);
        for(int i=2;i<=N;i++) {
            for(int j=1;j<=M;j++) Heap[j]=A[i][1]+S1[j];
            make_heap(Heap+1,Heap+M+1);
            for(int j=2;j<=M;j++) {
                for(int k=1;k<=M;k++) if(A[i][j]+S1[k]<Heap[1]){
                    pop_heap(Heap+1,Heap+M+1);
                    Heap[M]=A[i][j]+S1[k];
                    push_heap(Heap+1,Heap+M+1);
                }
            }
            for(int j=1;j<=M;j++) S1[j]=Heap[j];
            sort(S1+1,S1+M+1);
        }
        for(int i=1;i<M;i++) printf("%d ",S1[i]);
        printf("%d\n",S1[M]);
    }
    getchar();getchar();
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator