Click to open link
1073. Square Countrytime limit:1.0 Second
Memory limit:64 MB
There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament had passed a law on a land. According to the law each citizen of the country have a right to buy land. A land was sold in squares, surely. Moreover, a length of a square side must be a positive integer amount of meters. Buying a square of land with a side
aOne pays
a2Quadrics (a local currency) and gets a square certificate of a landowner. One citizen of the country have decided to invest all of his
NQuadrics into the land. He can, surely, do it, buying square pieces 1x1 meters. At the same time the citizen have requested to minimize an amount of pieces he buys: "It'll be a easier for me to pay taxes , "-he has said. He has bought the land successfully. Your task is to find out a number of certificates he has gotten. Inputthe only line contains a positive integer
N≤60, that's a number of quadrics that the citizen have invested. Outputthe only line contains a number of certificates so he has gotten. Sample
problem Author:Stanislav Vasilyev
problem Source:Ural State univerisity Personal Contest Online February ' 2001 Students Session
Tags:Dynamic programming()
give you a number n, let you ask the number at least by the number of square composition.
To complete the knapsack problem is: N represents the capacity of the backpack, each number of square represents the capacity to occupy, the value of 1, to find the minimum value.
0.031434 kb#include<stdio.h> #include <string.h> #include <algorithm> #define INF 0x3f3f3f3fusing Namespace Std;int dp[60007];int Main () { memset (dp,inf,sizeof (DP)); dp[0]=0; for (int i=1, i<=250; i++) for (int j=i*i; j<=60000; j + +) dp[j]=min (dp[j],dp[j-i*i]+1); int n; while (scanf ("%d", &n)!=eof) { printf ("%d\n", Dp[n]); } return 0;}
Ural 1073. Square Country Full Backpack