Guest User

Untitled

a guest
Nov 18th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <cstdio>
  16. #include <cmath>
  17. #include <cstdlib>
  18. #include <ctime>
  19.  
  20. using namespace std;
  21.  
  22. class AxonometricProjection {
  23. public:
  24.     int howManyWays(vector <int>, vector <int>);
  25. };
  26.  
  27. const long long MD = 1000000009LL;
  28. const int maxN = 60;
  29.  
  30. long long powmod(long long a, long long n) {
  31.     if (n == 0) return 1LL;
  32.     long long b = powmod(a, n / 2);
  33.     b = (b * b) % MD;
  34.     if (n % 2 == 0) return b;
  35.     return (a * b) % MD;
  36. }
  37.  
  38. int a[maxN], b[maxN], c[maxN][maxN];
  39. int n, m;
  40.  
  41. long long solve() {
  42.     int r = 0, s = 0;
  43.     long long res = 1;
  44.     for (int p = 10000; p >= 0; p --) {
  45.         int x = 0, y = 0;
  46.         for (int i = 0; i < n; i ++)
  47.             if (a[i] == p) x ++;
  48.         for (int i = 0; i < m; i ++)
  49.             if (b[i] == p) y ++;
  50.  
  51.         int u = x + r, v = y + s;
  52.         r += x, s += y;
  53.  
  54.         long long cur = 0;
  55.         for (int i = 0; i <= x; i ++)
  56.             for (int j = 0; j <= y; j ++) {
  57.                 int z = i * v + j * u - i * j;
  58.                 int t = x * v + y * u - x * y - z;
  59.                 long long A = powmod(p, z);
  60.                 long long B = powmod(p + 1, t);
  61.                 long long C = (A * B) % MD;
  62.                 C *= c[x][i], C %= MD;
  63.                 C *= c[y][j], C %= MD;
  64.                 if ((i + j) % 2 == 0) cur += C; else cur -= C;
  65.             }
  66.         cur %= MD;
  67.         if (cur < 0) cur += MD;
  68.         res *= cur, res %= MD;
  69.     }
  70.     return res;
  71. }
  72.  
  73. int AxonometricProjection::howManyWays(vector <int> heightsOfLeftView, vector <int> heightsOfFrontView) {
  74.     n = heightsOfLeftView.size();
  75.     m = heightsOfFrontView.size();
  76.     for (int i = 0; i <= 50; i ++) {
  77.         c[i][0] = 1;
  78.         for (int j = 1; j <= i; j ++)
  79.             c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MD;
  80.     }
  81.     for (int i = 0; i < n; i ++)
  82.         a[i] = heightsOfLeftView[i];
  83.     for (int i = 0; i < m; i ++)
  84.         b[i] = heightsOfFrontView[i];
  85.     return solve();
  86. }
  87.  
  88. <%:testing-code%>
  89. //Powered by [KawigiEdit] 2.0!
  90.  
Advertisement
Add Comment
Please, Sign In to add comment