Advertisement
florence20

Untitled

Apr 16th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.math.BigInteger;
  7.  
  8. public class Ursi {
  9.  
  10. public char[] charachets = new char[2000];
  11. public final static String INPUT_FILE = "src/ursi.in";
  12. public final static String OUTPUT_FILE = "src/ursi.out";
  13. long dp[][];
  14. int lungime = 0;
  15.  
  16. public void readInput() throws FileNotFoundException, IOException{
  17. int c;
  18. try {
  19. FileReader inputStream = new FileReader(INPUT_FILE);
  20. while ((c = inputStream.read()) != -1) {
  21. charachets[++lungime] = (char) c;
  22. }
  23. if (inputStream != null) {
  24. inputStream.close();
  25. }
  26.  
  27. } catch(IOException e){
  28. throw new RuntimeException(e);
  29. }
  30.  
  31. }
  32.  
  33. public void writeOutput(long res){
  34. try {
  35. PrintWriter pw = new PrintWriter(new File(OUTPUT_FILE));
  36. pw.printf("%d\n", (int)(res % (Math.pow(10, 9) + 7)));
  37.  
  38. pw.close();
  39. } catch( IOException e) {
  40. throw new RuntimeException(e);
  41. }
  42. }
  43. public long afisare(){
  44. System.out.println(charachets);
  45. System.out.println(lungime);
  46.  
  47. dp = new long[lungime][lungime];
  48. dp[1][0] = 1;
  49. for(int j = 1; j < lungime; j++){
  50. for(int i = 0; i < lungime; i++){
  51. if(charachets[j] == '_'){
  52. dp[i][j] = i * dp[i][j-1];
  53. }
  54. if(charachets[j] == '^'){
  55. if(i == 0) {
  56. dp[i][j] = dp[i+1][j-1];
  57. continue;
  58. }
  59. if(i == lungime - 1){
  60. continue;
  61. }
  62. dp[i][j] = (dp[i-1][j-1] + (i+1) * dp[i+1][j-1]);
  63. }
  64. }
  65. }
  66.  
  67. for(int i = 0; i < lungime; i++){
  68. for(int j = 0; j < lungime; j++){
  69. System.out.print(dp[i][j] + " ");
  70. }
  71. System.out.println("");
  72. }
  73. return dp[0][lungime - 1];
  74. }
  75.  
  76. public void solve() throws IOException{
  77. readInput();
  78. writeOutput(afisare());
  79. }
  80. public static void main(String[] args) throws IOException {
  81. new Ursi().solve();
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement