Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- string n;
- int dp[15][5];
- int rec(int i, int br){
- if((i==n.size())and(br==4)){
- return 1;
- }
- if(i==n.size()){
- return 0;
- }
- int result=0;
- if(dp[i][br]!=-1){
- return(dp[i][br]);
- }
- int k=0;
- if(n[i] == '0'){
- result+=rec(i+1, br+1);
- }
- else{
- for(int j=i; j<n.size(); j++){
- k=k*10+(n[j]-'0');
- if(k<=255){
- result+=rec(j+1, br+1);
- }
- }
- }
- dp[i][br]=result;
- return(result);
- }
- int main()
- {
- cin>>n;
- memset(dp, -1, sizeof dp);
- cout<<rec(0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement