Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.math.BigInteger;
- public class Ursi {
- public char[] charachets = new char[2000];
- public final static String INPUT_FILE = "src/ursi.in";
- public final static String OUTPUT_FILE = "src/ursi.out";
- long dp[][];
- int lungime = 0;
- public void readInput() throws FileNotFoundException, IOException{
- int c;
- try {
- FileReader inputStream = new FileReader(INPUT_FILE);
- while ((c = inputStream.read()) != -1) {
- charachets[++lungime] = (char) c;
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch(IOException e){
- throw new RuntimeException(e);
- }
- }
- public void writeOutput(long res){
- try {
- PrintWriter pw = new PrintWriter(new File(OUTPUT_FILE));
- pw.printf("%d\n", (int)(res % (Math.pow(10, 9) + 7)));
- pw.close();
- } catch( IOException e) {
- throw new RuntimeException(e);
- }
- }
- public long afisare(){
- System.out.println(charachets);
- System.out.println(lungime);
- dp = new long[lungime][lungime];
- dp[1][0] = 1;
- for(int j = 1; j < lungime; j++){
- for(int i = 0; i < lungime; i++){
- if(charachets[j] == '_'){
- dp[i][j] = i * dp[i][j-1];
- }
- if(charachets[j] == '^'){
- if(i == 0) {
- dp[i][j] = dp[i+1][j-1];
- continue;
- }
- if(i == lungime - 1){
- continue;
- }
- dp[i][j] = (dp[i-1][j-1] + (i+1) * dp[i+1][j-1]);
- }
- }
- }
- for(int i = 0; i < lungime; i++){
- for(int j = 0; j < lungime; j++){
- System.out.print(dp[i][j] + " ");
- }
- System.out.println("");
- }
- return dp[0][lungime - 1];
- }
- public void solve() throws IOException{
- readInput();
- writeOutput(afisare());
- }
- public static void main(String[] args) throws IOException {
- new Ursi().solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement