Advertisement
for-mile

icpc 3053

Nov 14th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1.  
  2. // Problem : icpc 3053
  3. // tegs : DP, nnumber theory
  4.  
  5. #include <algorithm>
  6. #include <cstdio>
  7. #include <deque>
  8. #include <queue>
  9. #include <string>
  10. #include <vector>
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14.  
  15. #define pb push_back
  16. #define mp make_pair
  17. #define sz(x) ((int)(x.size()))
  18. #define forn(i,n) for(int i = 0; i < (n); ++i)
  19. #define update(buf,val) buf = max((buf),val)
  20.  
  21. using namespace std;
  22. stringstream fakestream;
  23.  
  24. typedef long long llong;
  25. typedef unsigned long long ullong;
  26. typedef vector < int > vi;
  27. typedef vector < vi > vvi;
  28. typedef pair <int,int> pi;
  29.  
  30. bool getb(int num, int i )
  31. {
  32.     return (num >> i) & 1;
  33. }
  34. int setb(int num, int i )
  35. {
  36.     return num || (1 << i);
  37. }
  38.  
  39. bool is_contain_substr(const string& sub, int psub, const string& str, int pstr, int& mask)
  40. {
  41.     if(psub == sz( sub )) return true;
  42.     if(pstr == sz( str )) return false;
  43.     bool ifmiss =  is_contain_substr(sub, psub ,str, pstr + 1, mask);
  44.     bool ifget = is_contain_substr(sub, psub+ 1 ,str, pstr + 1, mask);
  45.     if(sub[ psub ] == str[ pstr ] )
  46.     {
  47.         if( ifget )
  48.             mask = setb(mask, pstr);
  49.         return   ifmiss || ifget;
  50.     }
  51.     else
  52.         return ifmiss;
  53. }
  54. string toString(int a)
  55. {
  56.     stringstream ss;
  57.     ss << a;
  58.     return ss.str;
  59. }
  60. int dp [ mask ]; // len
  61. int step [ mask ]; // next_step;
  62.  
  63. int getVal(int mask)
  64. {
  65.     string curn;
  66.     for(int i = 0; i < n; ++i)
  67.         if( getb( mask , i) )
  68.             curn.pb( data[ i ]);
  69.     int res = 1e7;
  70.     int n = strtoi( curn );
  71.     int corr_mask = 0;
  72.    
  73.     for(int d = 2; d * d <= n; ++d)
  74.     {
  75.        
  76.         if( n % d == 0
  77.             && is_contain_substr( toString( d ), 0, curn, 0, corr_mask))
  78.         {
  79.             for(int i = 0; i < sz><)
  80.             res = min( res, getVal(  ));
  81.         }
  82.        
  83.     }
  84.    
  85. }
  86. int main(){
  87. #ifdef LOCAL_PROJECT
  88.     //freopen("input","r",stdin);
  89. #endif
  90.     //freopen("output.txt","w",stdout);
  91.     ios_base::sync_with_stdio(false);
  92.     cin.tie(NULL);
  93.     int n;
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement