Guest User

Untitled

a guest
Feb 25th, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #define ull unsigned long long
  21. #define ll long long
  22. #define pii pair<int,int>
  23. #define pb(x) push_back(x)
  24. #define S(x) scanf("%d",&x)
  25. #define Sl(x) scanf("%lld",&x)
  26. #define M(x,i) memset(x,i,sizeof(x))
  27. #define F(i,a,n) for(int i=(a);i<(n);++i)
  28. #define FD(i,a,n) for(i=(a);i>=(n);--i)
  29. using namespace std;
  30.  
  31.  
  32. class Softmatchd2 {
  33. public:
  34. int dp[55];
  35.  
  36. int valid(char x,char y,char z){
  37.  
  38. if(x == y){
  39. return 1;
  40. }
  41.  
  42. if( z == 'a' || z=='A'){
  43. return (x == '0' && y == '1') || (x == '1' && y == '0') || (x=='2'&& y == '3') || (x=='3' && y == '2');
  44. }
  45.  
  46.  
  47. if( z == 'b' || z=='B'){
  48. return (x == '0' && y == '2') || (x == '2' && y == '0') || (x=='1'&& y == '3') || (x=='3' && y == '1');
  49. }
  50. return 0;
  51. }
  52.  
  53. int count(string s, string p) {
  54.  
  55. int lens = s.length();
  56. int lenp = p.length();
  57.  
  58. int ans = 0;
  59. F(i,0,lens){
  60.  
  61. if(i>=(lenp-1)){
  62. dp[i] = 1;
  63. }
  64.  
  65. F(j,0,i){
  66. int flg = 0;
  67.  
  68. if((i-lenp+1)<0)continue;
  69.  
  70. F(k,0,lenp){
  71. int ind1 = i - lenp + 1 + k;
  72.  
  73. if(ind1<=j){
  74.  
  75. int ind2 = ind1 - ( j - lenp + 1);
  76.  
  77. if(!valid(p[k],p[ind2],s[ind1])){
  78. flg = 1;
  79. break;
  80. }
  81. } else {
  82. break;
  83. }
  84. }
  85. if(flg == 0){
  86. dp[i] = max(dp[i],dp[j]+1);
  87. }
  88.  
  89. }
  90. ans = max(ans,dp[i]);
  91. }
  92.  
  93. return ans;
  94. }
  95. };
Add Comment
Please, Sign In to add comment