Created
April 26, 2016 08:06
-
-
Save PreSoichiSumi/563a52021ecba06efb9d34ec6186a99f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Main { | |
public static long happiness[][]=new long[2501][2501]; | |
public static int center=1250; | |
public static String S; | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
S=sc.nextLine(); | |
for(int i=0;i<2500;i++){ | |
Arrays.fill(happiness[i], Long.MIN_VALUE/2); | |
} | |
happiness[0][center]=0; | |
for(int i=0;i<S.length();i++){ | |
for(int x=-1200;x<1200;x++){ | |
if(S.charAt(i)=='+'){ | |
happiness[i+1][x+center]=happiness[i][x+center]+x; | |
}else if(S.charAt(i)=='-'){ | |
happiness[i+1][x+center]=happiness[i][x+center]-x; | |
}else{ | |
happiness[i+1][x+center]=Math.max(happiness[i][x+center-1],happiness[i][x+center+1]); | |
} | |
} | |
} | |
System.out.println(happiness[S.length()][center]); | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment