hihoCoder太阁最新面经算法竞赛13 register

Ended

Participants:132

Verdict:Accepted
Score:100 / 100
Submitted:2016-11-04 14:23:15

Lang:Java

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class Main {
  static int[] a,b;
  static int n,i,j,k,l,m,s;
  static int mod=1000000007;
  public static void main(String args[])  
  {  
    Scanner in=new Scanner(System.in);
    n=in.nextInt();m=in.nextInt();
    b=new int[n];
    s=0;
    for (i=0;i<n;i++){
      b[i]=in.nextInt();
      s+=b[i];
    }
    m=s-m;
    if (m%2!=0System.out.println(0); else {
      m/=2;
      a=new int[m+1];
      for (i=0;i<=m;i++)
        a[i]=0;
      a[0]=1;
      for (i=0;i<n;i++){
        for (j=m;j>=b[i];j--)
          a[j]=(a[j]+a[j-b[i]])%mod;
      }
      System.out.println(a[m]);
    }
    
      
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX