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 RE的心理交了 AC了 放心大胆地交吧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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator