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

ft : 下到的官方数据都过了; 用随机生成的1000组各种极端数据与ac了的程序做结果fc也全相同; 怎么还是wa呢?

Posted by happynp at 2008-07-05 17:36:04 on Problem 1505
有兴趣的拿去测下, 管理员 啊,帮看看

#include <iostream>
using namespace std;

#define MAX(a,b)   (((a) > (b)) ? (a) : (b))
#define  nMAX  505
#define  INT64_MAX ((__int64(1))<<62)

int  n, m, k;
int  books[nMAX];
__int64  sum[nMAX];
__int64  f[nMAX][nMAX];
int  c[nMAX];

__int64 dp(int m, int k)
// 前k名员工复制前m本书所需最小时间
{
	if( f[m][k] != -1 ) return f[m][k];
	if( k == 1 ) return sum[m];
	f[m][k] = INT64_MAX;
	int t;
	__int64 v;
	for(t=k-1; t<m; t++) {
		v = MAX( dp(t, k-1), sum[m] - sum[t] );
		if( v < f[m][k] )
			f[m][k] = v;
	}
	return f[m][k];
}

void solve(int m, int k)
{
	dp(m, k);
	const __int64 cost = f[m][k];
	__int64 t = 0;
	int index = k - 1;
	for(int i=m; i>=1; i--){
		if( t + (__int64)books[i] <= cost && i > index ) {
			t += (__int64)books[i];
		}
		else{
			c[index--] = i;
			t = (__int64)books[i];
		}
	}
}

void outPut()
{	
	int i, index = 1;
	for(i=1; i<m; i++){
		printf("%d ", books[i]);
		if( i == c[index] ){
			printf("/ ");
			index++;
		}
	}
	printf("%d\n", books[m]);
}

int main()
{
    scanf("%d", &n);
	int i, j;
    for (i=0; i<n; i++) 
	{	
		memset(f, -1, sizeof(f));
		memset(c, 0, sizeof(c));
        scanf("%d%d", &m, &k);       
        for(j=1; j<=m; j++)
			scanf("%d", &books[j]);
		sum[1] = (__int64)books[1];
		for(j=2; j<=m; j++) 
			sum[j] = sum[j-1] + (__int64)books[j];
		solve(m, k);
		outPut();
    }
	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