SHARE
TWEET

WhiteHat_ACM

a guest Sep 24th, 2014 340 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<cstring>
  4. #define maxn 5000
  5. #define oo 10000000
  6. #define FOR(i,a,b) for(int i= a;i <= b;i++)
  7. #define REP(i,n) for(int i = 0; i < n ;i++)
  8. using namespace std ;
  9. typedef vector<int> vi ;
  10. int F[maxn][maxn] ;
  11. void process(int n, int m)
  12. {
  13.     FOR(i,1,n) F[i][i] = 1;
  14.     FOR(i,1,n)
  15.         FOR(j,i+1,m)
  16.         {
  17.             F[i][j] = oo ;
  18.             FOR(k,1,i/2) F[i][j] = min(F[i][j] ,F[k][j]+F[i-k][j]) ;
  19.             FOR(k,1,j/2) F[i][j] = min(F[i][j],F[i][k]+F[i][j-k]);
  20.             F[j][i] = F[i][j];
  21.         }
  22.     cout << F[n][m] ;
  23. }
  24. int main()
  25. {
  26.     int n, m ;
  27.     cin >> n >> m ;
  28.     if ( n > m )swap(n,m);
  29.     process(n,m) ;
  30.     system("pause");
  31.     return 1;
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top