daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6.  
  7. public class Main{
  8.     public static void main(String args[]) throws IOException{
  9.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10.         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
  11.        
  12.         int num = Integer.parseInt(br.readLine());
  13.        
  14.         int[][] arr = new int[101][10];
  15.        
  16.         for(int i=1;i<10;i++) {
  17.             arr[1][i] = 1;
  18.         }
  19.        
  20.         for(int i=2;i<=num;i++) {
  21.             for(int j=0;j<10;j++) {
  22.                 if(j==0) arr[i][j] = arr[i-1][j+1];
  23.                 else if(j==9) arr[i][j] = arr[i-1][j-1];
  24.                 else {
  25.                     arr[i][j] = arr[i-1][j-1] + arr[i-1][j+1];
  26.                 }
  27.                 arr[i][j] = arr[i][j]%1000000000;
  28.             }
  29.         }
  30.        
  31.         int res = 0;
  32.         for(int i=0;i<10;i++) {
  33.             res = res+arr[num][i];
  34.             res = res%1000000000;
  35.         }
  36.        
  37.         bw.write(res+"");
  38.         bw.flush();
  39.         bw.close();
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top