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

Same as the Coin Change Problem
Posted by Erik Arakelyan(AUA) 17 Jun 2016 15:08
#include <iostream>
#include <cmath>
using namespace std;

int minCoins(int coins[], int m, int V)
{
    int table[V+1];

    table[0] = 0;

    for (int i=1; i<=V; i++)
        table[i] = INT_MAX;

    for (int i=1; i<=V; i++)
    {
        for (int j=0; j<m; j++)
            if (coins[j] <= i)
            {
                int subResult = table[i-coins[j]];
                if (subResult != INT_MAX && subResult + 1 < table[i])
                    table[i] = subResult + 1;
            }
    }
    return table[V];
}

int main()
{
    int V;
    cin>>V;
    int coins[1000];
    int i;


    for(i=1;i<=sqrt(V);i++)
    {
        coins[i-1] = (i)*(i);
    }
    int m = sqrt(V);

    cout<< minCoins(coins, m, V)<<endl;
    return 0;
}



This problem can be translated to get the minimum amout of coins to get the value N.(We must just check that the coins are the actual square numbers).