শুক্রবার, ৯ নভেম্বর, ২০১২

light oj---1004 - Monkey Banana Problem



  1. #include<stdio.h>
  2. #include<string.h>
  3. #define LL long long
  4. LL dp[210][210],num[210][210],n;
  5. LL max(LL a,LL b)
  6.  {
  7.      if(a>b) return a;
  8.      return b;
  9.  }
  10. LL call(LL a,LL b)
  11.  {
  12.      if(num[a][b]==0) return 0;
  13.      if(dp[a][b]!=-1) return dp[a][b];
  14.      LL ret=num[a][b];
  15.      if(a<=n)
  16.       ret+=max(call(a-1,b),call(a-1,b-1));
  17.      else
  18.      ret+=max(call(a-1,b),call(a-1,b+1));
  19.      return dp[a][b]=ret;
  20.  }
  21. int main()
  22.  {
  23.      int t;
  24.      scanf("%d",&t);
  25.      for(int i=1;i<=t;i++)
  26.       {
  27.           scanf("%lld",&n);
  28.           for(int j=0;j<=200;j++)
  29.             for(int k=0;k<=200;k++)
  30.               {
  31.                    num[j][k]=0;
  32.                    dp[j][k]=-1;
  33.               }
  34.           for(int j=1;j<n;j++)
  35.            for(int k=1;k<=j;k++)
  36.              scanf("%lld",&num[j][k]);
  37.           for(int j=n;j<2*n;j++)
  38.            for(int k=1;k<=2*n-j;k++)
  39.              scanf("%lld",&num[j][k]);
  40.           LL ans=num[2*n-1][1];
  41.           ans+=max(call(2*n-2,1),call(2*n-2,2));
  42.           printf("Case %d: %lld\n",i,ans);
  43.       }
  44.       return 0;
  45.  }

বৃহস্পতিবার, ৮ নভেম্বর, ২০১২

ligjt oj---1003 - Drunk



  1. #include <algorithm>
  2. #include <cassert>
  3. #include <cctype>
  4. #include <cfloat>
  5. #include <climits>
  6. #include <cmath>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <limits>
  12. #include <map>
  13. #include <queue>
  14. #include <set>
  15. #include <sstream>
  16. #include <stack>
  17. #include <string>
  18. #include <utility>
  19. #include <vector>
  20. #define G getchar()
  21. #define FOR(i,t) for(i=1;i<=t;i++)
  22. #define FORO(j,n) for(j=0;j<n;j++)
  23. #define EPS DBL_EPSILON
  24. #define abs(x) (((x)<0)?-(x):(x))
  25. #define ZERO(x) (abs(x) < EPS)
  26. #define EQ(a,b) (ZERO((a)-(b)))
  27. #define max(a,b) (a)>(b)?(a):(b)
  28. #define min(a,b) (a)<(b)?(a):(b)
  29. #define memo(a,v) memset(a,v,sizeof(a))
  30. #define PI 2*acos(0.0)
  31. #define all(a) a.begin(),a.end()
  32. #define EPS 1e-8
  33. #define INF -1U >> 1
  34. #define LL int int
  35. #define NL puts("")
  36. #define MAX 30001
  37. using namespace std;
  38. map<string ,int >m;
  39. vector<int >v[20010];
  40. //string st1,st2;
  41. char in[20010];
  42. int j=0;
  43. void fix(int i)
  44. {
  45.     int k;
  46.     in[i]=-1;
  47.     FORO(k,v[i].size())
  48.            {
  49.                in[v[i][k]]--;
  50.            }
  51. }
  52. bool comp(int a,int b)
  53.  {
  54.      if(a>b) return true;
  55.      return false;
  56.  }
  57. int main()
  58.  {
  59.      int i,t;
  60.      scanf("%d",&t);
  61.      FOR(i,t)
  62.       {
  63.           m.clear();
  64.           memo(in,0);
  65.          int a,k;
  66.          j=0;
  67.           scanf("%d",&a);
  68.           while(a--)
  69.            {
  70.                G;
  71.                char st1[100],st2[100];
  72.                scanf("%s %s",&st1,&st2);
  73.                if(!(m.count(st1)>0))
  74.                 m[st1]=j++;
  75.                if(!(m.count(st2)>0))
  76.                 m[st2]=j++;
  77.                v[m[st1]].push_back(m[st2]);
  78.                in[m[st2]]++;
  79.            }
  80.           int fin;
  81.          fin = 0;
  82.          while(fin<j)
  83.           {
  84.             FORO(k,j)
  85.              if(in[k]==0)
  86.                   fix(k);
  87.             fin++;
  88.           }
  89.          //FORO(k,j) printf("%d ",in[k]);
  90.          //NL;
  91.          sort(in,in+j,comp);
  92.          if(in[1]>0)
  93.           printf("Case %d: No\n",i);
  94.          else printf("Case %d: Yes\n",i);
  95.        FORO(k,j)
  96.         v[k].clear();
  97.       }
  98.       return 0;
  99.  }