Advertisement
Josif_tepe

Untitled

Jan 26th, 2022
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. string n;
  5. int dp[15][5];
  6. int rec(int i, int br){
  7.     if((i==n.size())and(br==4)){
  8.  
  9.         return 1;
  10.     }
  11.  
  12.     if(i==n.size()){
  13.         return 0;
  14.     }
  15.  
  16.     int result=0;
  17.  
  18.     if(dp[i][br]!=-1){
  19.         return(dp[i][br]);
  20.     }
  21.     int k=0;
  22.     if(n[i] == '0'){
  23.         result+=rec(i+1, br+1);
  24.     }
  25.     else{
  26.     for(int j=i; j<n.size(); j++){
  27.     k=k*10+(n[j]-'0');
  28.         if(k<=255){
  29.             result+=rec(j+1, br+1);
  30.         }
  31.     }
  32.     }
  33.     dp[i][br]=result;
  34.     return(result);
  35. }
  36. int main()
  37. {
  38.     cin>>n;
  39.     memset(dp, -1, sizeof dp);
  40.     cout<<rec(0, 0);
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement