Advertisement
a-dobrev

Legs Minkov

Apr 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.00 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.InputMismatchException;
  3.  
  4. public class Test {
  5.     public static void main(String[] args) {
  6.         InputReader reader = new InputReader();
  7.         OutputWriter writer = new OutputWriter();
  8.         int n = reader.readInt();
  9.         int[] legs = {2, 5, 7};
  10.  
  11.         int[] combinations = new int[n + 1];
  12.         combinations[0] = 1;
  13.  
  14.         for (int i = 0; i < 3; i++) {
  15.             for (int j = 1; j < combinations.length; j++) {
  16.                 if (j >= legs[i]) {
  17.                     combinations[j] = combinations[j] + combinations[j - legs[i]];
  18.                 }
  19.             }
  20.         }
  21.  
  22.         writer.printLine(combinations[n]);
  23.         writer.close();
  24.     }
  25.  
  26.     static class InputReader {
  27.         private InputStream stream;
  28.         private byte[] buf = new byte[1024];
  29.         private int curChar;
  30.         private int numChars;
  31.  
  32.         InputReader() {
  33.             this.stream = System.in;
  34.         }
  35.  
  36.         int read() {
  37.             if (numChars == -1)
  38.                 throw new InputMismatchException();
  39.             if (curChar >= numChars) {
  40.                 curChar = 0;
  41.                 try {
  42.                     numChars = stream.read(buf);
  43.                 } catch (IOException e) {
  44.                     throw new InputMismatchException();
  45.                 }
  46.                 if (numChars <= 0)
  47.                     return -1;
  48.             }
  49.             return buf[curChar++];
  50.         }
  51.  
  52.         int readInt() {
  53.             int c = read();
  54.             while (isSpaceChar(c)) {
  55.                 c = read();
  56.             }
  57.             int sgn = 1;
  58.             if (c == '-') {
  59.                 sgn = -1;
  60.                 c = read();
  61.             }
  62.             int res = 0;
  63.             do {
  64.                 if (c < '0' || c > '9') {
  65.                     throw new InputMismatchException();
  66.                 }
  67.                 res *= 10;
  68.                 res += c - '0';
  69.                 c = read();
  70.             } while (!isSpaceChar(c));
  71.             return res * sgn;
  72.         }
  73.  
  74.         long readLong() {
  75.             int c = read();
  76.             while (isSpaceChar(c)) {
  77.                 c = read();
  78.             }
  79.             int sgn = 1;
  80.             if (c == '-') {
  81.                 sgn = -1;
  82.                 c = read();
  83.             }
  84.             long res = 0;
  85.             do {
  86.                 if (c < '0' || c > '9') {
  87.                     throw new InputMismatchException();
  88.                 }
  89.                 res *= 10;
  90.                 res += c - '0';
  91.                 c = read();
  92.             } while (!isSpaceChar(c));
  93.             return res * sgn;
  94.         }
  95.  
  96.         double readDouble() {
  97.             int c = read();
  98.             while (isSpaceChar(c)) {
  99.                 c = read();
  100.             }
  101.             int sgn = 1;
  102.             if (c == '-') {
  103.                 sgn = -1;
  104.                 c = read();
  105.             }
  106.             double res = 0;
  107.             while (!isSpaceChar(c) && c != '.' && c != ',') {
  108.                 if (c == 'e' || c == 'E') {
  109.                     return res * Math.pow(10, readInt());
  110.                 }
  111.                 if (c < '0' || c > '9') {
  112.                     throw new InputMismatchException();
  113.                 }
  114.                 res *= 10;
  115.                 res += c - '0';
  116.                 c = read();
  117.             }
  118.             if (c == '.' || c == ',') {
  119.                 c = read();
  120.                 double m = 1;
  121.                 while (!isSpaceChar(c)) {
  122.                     if (c == 'e' || c == 'E') {
  123.                         return res * Math.pow(10, readInt());
  124.                     }
  125.                     if (c < '0' || c > '9') {
  126.                         throw new InputMismatchException();
  127.                     }
  128.                     m /= 10;
  129.                     res += (c - '0') * m;
  130.                     c = read();
  131.                 }
  132.             }
  133.             return res * sgn;
  134.         }
  135.  
  136.         String readLine() {
  137.             int c = read();
  138.             while (isSpaceChar(c))
  139.                 c = read();
  140.             StringBuilder res = new StringBuilder();
  141.             do {
  142.                 res.appendCodePoint(c);
  143.                 c = read();
  144.             } while (!isSpaceChar(c));
  145.             return res.toString();
  146.         }
  147.  
  148.         boolean isSpaceChar(int c) {
  149.             return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  150.         }
  151.     }
  152.  
  153.     static class OutputWriter {
  154.         private final PrintWriter writer;
  155.  
  156.         OutputWriter() {
  157.             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  158.         }
  159.  
  160.         void print(Object... objects) {
  161.             for (int i = 0; i < objects.length; i++) {
  162.                 if (i != 0)
  163.                     writer.print(' ');
  164.                 writer.print(objects[i]);
  165.             }
  166.         }
  167.  
  168.         void printLine(Object... objects) {
  169.             print(objects);
  170.             writer.println();
  171.         }
  172.  
  173.         void close() {
  174.             writer.close();
  175.         }
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement