Advertisement
ec1117

Untitled

Jul 3rd, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.io.BufferedReader;
  4. import java.awt.Point;
  5.  
  6. public class team{
  7. public static final String TASKNAME = "team";
  8. public static long mod= 1000000009;
  9. public static Debug db;
  10.  
  11. public static void main(String[] args) throws IOException {
  12. // InputReader in = new InputReader(System.in);
  13. // PrintWriter out = new PrintWriter(System.out);
  14. InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
  15. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
  16. Autocompletion solver = new Autocompletion();
  17. db=new Debug(System.getSecurityManager()==null);
  18. solver.solve(1, in, out);
  19. out.close();
  20. }
  21. static class Autocompletion {
  22.  
  23. public void solve(int testNumber, InputReader in, PrintWriter out) {
  24. int n=in.nextInt();
  25. int m=in.nextInt();
  26. int k=in.nextInt();
  27. long dp[][][]=new long[n][m][k+2];
  28. long fj[]=new long[n];
  29. long fp[]=new long[m];
  30. for(int i=0;i<n;i++) {
  31. fj[i]=in.nextLong();
  32. }
  33. for(int i=0;i<m;i++) {
  34. fp[i]=in.nextLong();
  35. }
  36. for(int i=0;i<=k;i++) {
  37. for(int j=0;j<n;j++) {
  38. for(int l=0;l<m;l++) {
  39. if(j!=0) {
  40. dp[j][l][i]=(dp[j][l][i]+dp[j-1][l][i])%mod;
  41. }
  42. if(l!=0) {
  43. dp[j][l][i]=(dp[j][l][i]+dp[j][l-1][i])%mod;
  44. }
  45. if(l!=0 && j!=0) {
  46. dp[j][l][i]=(dp[j][l][i]-dp[j-1][l-1][i])%mod;
  47. }
  48. if(fj[j]>fp[l]) {
  49. if(i==0) {
  50. dp[j][l][i+1]=1;
  51. }
  52. else if(j==0 || l==0) {//not possible since i>0
  53. continue;
  54. }
  55. else {
  56. dp[j][l][i+1]=(dp[j][l][i+1]+dp[j-1][l-1][i])%mod;
  57. }
  58. }
  59. }
  60. }
  61. }
  62. long sum=0;
  63. for(int i=0;i<n;i++) {
  64. for(int j=0;j<m;j++) {
  65. if(fj[i]>fp[j] && i!=0 && j!=0){
  66. sum=(sum+dp[i-1][j-1][k-1])%mod;
  67. }
  68. }
  69. }
  70. out.println(sum%mod);
  71. }
  72.  
  73. private void timeout() {
  74. ArrayList<Integer> arr=new ArrayList<Integer>();
  75. for(int i=0;i<Integer.MAX_VALUE;i++) {
  76. arr.add(i);
  77. }
  78. }
  79. }
  80. static class Pair implements Comparable<Pair>{
  81. int x;
  82. int y;
  83. Pair(int a, int b){
  84. x=a;
  85. y=b;
  86. }
  87. @Override
  88. public int compareTo(Pair arg0) {
  89. if(arg0.x!=x)return x-arg0.x;
  90. return y-arg0.y;
  91. }
  92. }
  93. static class Triple implements Comparable<Triple>{
  94. int x;
  95. int y;
  96. int z;
  97. Triple(int a, int b, int c){
  98. x=a;
  99. y=b;
  100. z=c;
  101. }
  102. @Override
  103. public int compareTo(Triple arg0) {
  104. if(arg0.x!=x)return x-arg0.x;
  105. return y-arg0.y;
  106. }
  107. }
  108.  
  109. static class InputReader {
  110. public BufferedReader reader;
  111. public StringTokenizer tokenizer;
  112.  
  113. public InputReader(InputStream stream) {
  114. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  115. tokenizer = null;
  116. }
  117.  
  118. public String next() {
  119. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  120. try {
  121. tokenizer = new StringTokenizer(reader.readLine());
  122. } catch (IOException e) {
  123. throw new RuntimeException(e);
  124. }
  125. }
  126. return tokenizer.nextToken();
  127. }
  128.  
  129. public int nextInt() {
  130. return Integer.parseInt(next());
  131. }
  132. public long nextLong() {
  133. return Long.parseLong(next());
  134. }
  135. public int[] nextIntArr(int n) {
  136. int arr[]=new int[n];
  137. for(int i=0;i<n;i++) {
  138. arr[i]=this.nextInt();
  139. }
  140. return arr;
  141. }
  142. }
  143. public static class Debug {
  144. private boolean allowDebug;
  145.  
  146. public Debug(boolean allowDebug) {
  147. this.allowDebug = allowDebug;
  148. }
  149.  
  150. private void outputName(String name) {
  151. System.out.print(name + " = ");
  152. }
  153.  
  154. public void debug(String name, int x) {
  155. if (!allowDebug) {
  156. return;
  157. }
  158.  
  159. outputName(name);
  160. System.out.println("" + x);
  161. }
  162.  
  163. public void debug(String name, long x) {
  164. if (!allowDebug) {
  165. return;
  166. }
  167. outputName(name);
  168. System.out.println("" + x);
  169. }
  170.  
  171. public void debug(String name, double x) {
  172. if (!allowDebug) {
  173. return;
  174. }
  175. outputName(name);
  176. System.out.println("" + x);
  177. }
  178.  
  179. public void debug(String name, int[] x) {
  180. if (!allowDebug) {
  181. return;
  182. }
  183. outputName(name);
  184. System.out.println(Arrays.toString(x));
  185. }
  186.  
  187. public void debug(String name, long[] x) {
  188. if (!allowDebug) {
  189. return;
  190. }
  191. outputName(name);
  192. System.out.println(Arrays.toString(x));
  193. }
  194.  
  195. public void debug(String name, double[] x) {
  196. if (!allowDebug) {
  197. return;
  198. }
  199. outputName(name);
  200. System.out.println(Arrays.toString(x));
  201. }
  202.  
  203. public void debug(String name, Pair[] x) {
  204. if (!allowDebug) {
  205. return;
  206. }
  207. outputName(name);
  208. StringBuilder sb = new StringBuilder("[");
  209. int cnt=0;
  210. for(Pair y:x) {
  211. sb.append('('+y.x+","+y.y+')');
  212. if (cnt != x.length-1)sb.append(", ");
  213. cnt++;
  214. }
  215. System.out.println(sb.append("]").toString());
  216. }
  217.  
  218. public void debug(String name, Object x) {
  219. if (!allowDebug) {
  220. return;
  221. }
  222. outputName(name);
  223. System.out.println("" + x);
  224. }
  225.  
  226. public void debug(String name, Object... x) {
  227. if (!allowDebug) {
  228. return;
  229. }
  230. outputName(name);
  231. System.out.println(Arrays.deepToString(x));
  232. }
  233. }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement