Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. static const double eps = 1e-5;
  5. static const int INFTY = (1<<21);
  6. static const ll LLINFTY = (1LL<<53);
  7. #define REP(i,m,n) for(int i=m;i<int(n);i++)
  8. #define rep(i,n) REP(i,0,n)
  9. #define MAX (10000)
  10. bool dp[31][MAX+1];
  11. int V;
  12. vector<string> arc;
  13. class AllCycleLengths {
  14. public:
  15. void solve(int v){
  16. memset(dp,0,sizeof(dp));
  17. dp[v][0] = true;
  18. for(int c=0;c<MAX;c++){
  19. for(int id=0;id<V;id++){
  20. if( !dp[id][c] ) continue;
  21. for(int nex = 0;nex<V;nex++){
  22. if( arc[id][nex] == 'Y' )
  23. dp[nex][c+1] = true;
  24. }
  25. }
  26. }
  27. }
  28. string findAll(vector <string> arcs) {
  29. string res="";
  30. V = arcs.size();
  31. arc = arcs;
  32. string vc = string(MAX-1,'0');
  33. for(int v=0;v<V;v++){
  34. solve(v);
  35. for(int i=1;i<MAX;i++){
  36. if( dp[v][i] )
  37. vc[i-1] = '1';
  38. }
  39. }
  40. string comp = "1";
  41. bool f = false;
  42. for(int cc=0;cc<V;cc++){
  43. int cnt = 0;
  44. int be=0;
  45. for(int i=0;i<(int)vc.size()-cc;i++){
  46. if( vc.substr(i,cc+1) == comp ){
  47. if( cnt == 0 ) be = i;
  48. i+=cc;
  49. cnt++;
  50. }
  51. else cnt = 0;
  52. if( cnt == V+1 ){
  53. f=true;
  54. if( be ) res = vc.substr(0,be);
  55. res += "(" + comp + ")";
  56. }
  57. }
  58. comp = "0" + comp;
  59. if( res != "" ) break;
  60. }
  61. if(!f) res = "(0)";
  62. return res;
  63. }
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement