程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> ural 1073. Square Country 完全背包

ural 1073. Square Country 完全背包

編輯:關於C++
 

1073. Square Country

Time 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 has passed a law about a land. According to the law each citizen of the country has a right to buy land. A land is 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 a one pays a2 quadrics (a local currency) and gets a square certificate of a landowner. One citizen of the country has decided to invest all of his N quadrics into the land. He can, surely, do it, buying square pieces 1 × 1 meters. At the same time the citizen has requested to minimize an amount of pieces he buys: It will be 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.

Input

The only line contains a positive integer N ≤ 60 000 , that is a number of quadrics that the citizen has invested.

Output

The only line contains a number of certificates that 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 ( )
給你一個數n,讓你求這個數最少由多少個數的平方構成。 轉為完全背包問題就是:n代表背包的容量,每個數的平方代表要占用的容量,價值為1,求最小價值。
//0.031	434 KB
#include
#include
#include
#define inf 0x3f3f3f3f
using 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
,dp[n]);
    }
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved