Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class saw_bm {
- FastScanner in;
- PrintWriter out;
- void solve() {
- int n = in.nextInt();
- final int MOD = (int) 1e9 + 7;
- int[] dp1 = new int[n + 1];
- dp1[n] = 1;
- int[] dp2 = new int[n + 1];
- for (int i = 0; i < n; i++) {
- Arrays.fill(dp2, 0);
- int total = n - i;
- if (i % 2 == 0) {
- int numberOfWays = 0;
- for (int cur = total - 1; cur >= 0; cur--) {
- numberOfWays += dp1[cur + 1];
- if (numberOfWays >= MOD)
- numberOfWays -= MOD;
- dp2[cur] += numberOfWays;
- if (dp2[cur] >= MOD)
- dp2[cur] -= MOD;
- }
- } else {
- int numberOfWays = 0;
- for (int cur = 0; cur< total; cur++) {
- numberOfWays += dp1[cur];
- if (numberOfWays >= MOD)
- numberOfWays -= MOD;
- dp2[cur] += numberOfWays;
- if (dp2[cur] >= MOD)
- dp2[cur] -= MOD;
- }
- }
- int[] tmp = dp1;
- dp1 = dp2;
- dp2 = tmp;
- }
- long res = 0;
- for (int i = 0; i <= n; i++) {
- res += dp1[i];
- }
- out.println(res % MOD);
- }
- void run() {
- try {
- in = new FastScanner(new File("saw.in"));
- out = new PrintWriter(new File("saw.out"));
- solve();
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- void runIO() {
- in = new FastScanner(System.in);
- out = new PrintWriter(System.out);
- solve();
- out.close();
- }
- class FastScanner {
- BufferedReader br;
- StringTokenizer st;
- public FastScanner(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- public FastScanner(InputStream f) {
- br = new BufferedReader(new InputStreamReader(f));
- }
- String next() {
- while (st == null || !st.hasMoreTokens()) {
- String s = null;
- try {
- s = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (s == null)
- return null;
- st = new StringTokenizer(s);
- }
- return st.nextToken();
- }
- boolean hasMoreTokens() {
- while (st == null || !st.hasMoreTokens()) {
- String s = null;
- try {
- s = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (s == null)
- return false;
- st = new StringTokenizer(s);
- }
- return true;
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- long nextLong() {
- return Long.parseLong(next());
- }
- }
- public static void main(String[] args) {
- new saw_bm().runIO();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement