ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1073. Square Country

Help anybody
Posted by ELDVN 20 Dec 2015 23:22
Wheres my wrong? help pleas
#include <bits/stdc++.h>

const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;

using namespace std;

int n;
int dp[maxn]={-1};

int calc(int n){
    int res=n;
    dp[0]=0;
    if(dp[n] != -1)
        return dp[n];
     for(int i=1; i*i <= n; i++){
         res=min(res,1+calc(n-i*i));
     }
    return dp[n]=res;
}

int main(){
    scanf("%d",&n);
    printf("%d\n", calc(n));

    return 0;
}

Edited by author 20.12.2015 23:27