ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1029. Ministry

Why I got a WA
Posted by yuanlingxing 17 Jul 2003 14:42
#include<iostream.h>

int nroom;
int nfloor;
int price[100][500];
int from[100][500];
int tmp[500];

void output(int a,int index){
    if(index==0){
        cout<<a+1<<endl;
        return;
    }
    if(a==from[index][a])
        output(a,index-1);
    else
        output(from[index][a],index);
    cout<<a+1<<endl;
}


void sol(int index){
    if(index==nfloor)
        return;
    int i;
    for(i=0 ; i<nroom ; i++){
        from[index][i]=i;
        tmp[i]+=price[index][i];
    }
    int tmpi;
    for(i=0 ; i<nroom ; i++){
        tmpi=i-1;
        while(tmpi>=0){
            if( tmp[tmpi]>(tmp[tmpi+1]+price[index]
[tmpi]) ){
                tmp[tmpi]=(tmp[tmpi+1]+price
[index][tmpi]);
                from[index][tmpi]=tmpi+1;
                tmpi--;
            }
            else break;
        }
        tmpi=i+1;
        while(tmpi<nroom){
            if( tmp[tmpi]>(tmp[tmpi-1]+price[index]
[tmpi]) ){
                tmp[tmpi]=(tmp[tmpi-1]+price
[index][tmpi]);
                from[index][tmpi]=tmpi-1;
                tmpi++;
            }
            else break;
        }
        i=tmpi-1;
    }
    sol(index+1);
}

int main(){
    cin>>nfloor>>nroom;
    int i,j;
    for(i=0 ; i<nfloor ; i++)
        for(j=0 ; j<nroom ; j++)
            cin>>price[i][j];
    for(i=0 ; i<nroom ; i++)
        tmp[i]=price[0][i];
    sol(1);
    int min,pmin;
    min=1000000000;
    for(i=0 ; i<nroom ; i++){
        if(tmp[i]<min){
            min=tmp[i];
            pmin=i;
        }
    }
    output(pmin,nfloor-1);
    return 1;
}