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

抱着必定WA RE的心理交了 AC了 放心大胆地交吧

Posted by xuchang at 2011-03-31 15:39:06 on Problem 1837 and last updated at 2011-03-31 15:40:44
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String args[]) throws Exception {
		Scanner cin = new Scanner(System.in);
		int c=cin.nextInt();
		int g=cin.nextInt();
		int hook[]=new int[c];
		int weight[]=new int[g];
		int[][] dp=new int[g+1][10000];
		for(int i=0;i<c;i++)
			hook[i]=cin.nextInt();
		for(int i=0;i<g;i++)
			weight[i]=cin.nextInt();
		dp[0][0]=1;
	    for(int i=0;i<g;i++)
	    {
	    	for(int j=0;j<c;j++)
	    	{
	    		int v=weight[i]*hook[j];
	    		if(v>=0)
	    		{
	    			for(int k=0;k<=4875-v;k++)
	    			{
	    				dp[i+1][k+v]+=dp[i][k];
	    			}
	    			for(int k=5000;k<=9875;k++)
	    			{
	    				if(k-v>=5000)
	    					dp[i+1][k-v]+=dp[i][k];
	    				else
	    					dp[i+1][5000-k+v]+=dp[i][k];
	    			}
	    		}
	    		else
	    		{
	    			for(int k=0;k<=4875;k++)
	    			{
	    				if(k+v>=0)
	    					dp[i+1][k+v]+=dp[i][k];
	    				else
	    					dp[i+1][5000-k-v]+=dp[i][k];
	    			}
	    			for(int k=5000;k<=9875+v;k++)
	    			{
	    				dp[i+1][k-v]+=dp[i][k];
	    			}
	    		}
	    	}
	    }
	    System.out.println(dp[g][0]+dp[g][5000]);
           //5000以上是负数空间,因此5000也算状态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