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

55用了楼大叔PPT的方法,多重背包化0-1和bitset,还是超(代码)

Posted by userfriendly at 2009-02-19 00:47:37 on Problem 1742 and last updated at 2009-02-19 01:06:11
O(NMlgC)

bitset<100010> dp[2];//做滚动数组
v[], vp //做物品代价数组和尾指针

是不是这部分还有什么能挖的?

		for(int i=0; i<vp; i++)
		{
			x=i%2; y=(i+1)%2;
			dp[y]=dp[x];
			for(int j=v[i]; j<=m; j++)
				if(!dp[y][j] && dp[x][j-v[i]])
					dp[y].set(j);
		}


输出dp[y].count()-1

答案是没错的

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