Ural 1073. Square Country Full Backpack

Source: Internet
Author: User

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
input Output
344
3
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.