Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一直WA!牛人帮下小弟,自测的数据始终不奏效。这里面,time[i]表示i船回到港口开始继续运送car的最短时间。 同时设i次最后一次运送了j个car,这样自问题则为time[i-j]了。 #include <iostream> #include <fstream> #define in cin using namespace std; const int MAX = 1441; const int INFINITE = 100000000; int arr[MAX], time[MAX], n, t, m, solution[MAX]; int gettime ( int num ) { if ( num <= 0 ) return 0; if ( time[num] > 0 ) return time[num]; if ( num == 1 ) { solution[num] = 1; time[num] = arr[num] + 2 * t; return time[num]; } int min = INFINITE; for ( int i = 1; i <= n; i++ ) { int v = gettime ( num - i ); time[num - i] = v; if ( v <= arr[num] ) v = arr[num] + 2 * t; else v += 2 * t; if ( min > v ) { solution[num] = i; min = v; } } time[num] = min; return time[num]; } int main () { int c, i; ifstream in ( "2336.txt" ); for ( in >> c; c > 0; c-- ) { in >> n >> t >> m; for ( i = 1; i <= m; i++ ) in >> arr[i]; memset ( solution, 0, sizeof ( solution ) ); memset ( time, 0, sizeof ( time ) ); int cost = gettime ( m ), count = 0; while ( m > 0 ) {//cout<<solution[m] << " "; count++; m -= solution[m]; }//cout<<endl; cout << cost - t << " " << count << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator