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

题意:

在一个正方形的国度里住着正方形的人.在这个国家里,所有的东西都是正方形的.该国的国会通过了一项关于土地的法律,依照法律,该国的国民有买土地的权利,当然,土地的买卖也是按照正方形进行.而且,买卖的土地的边长必须是整米数,每买一块土地,必须付款(用当地的钱币),每买一块地,买主会得到一份土地所有者的证明.一个市民打算把他的钱投资到土地上,因为都只能买边长为整数的正方形地,他希望土地的块数最小.他认为:"这使我在交税时,更方便",他终于购地成功. 你的任务是找出他购地的块数,以便发给他地主证书.

输入包含一个自然数N,N<=60000,表示他能买多少方土地

思路,递归方程dp[i]={dp[k]|k=i-j*j,1<=j*j<=i}

AC代码:

 #include<iostream>
#include<cstdio> using namespace std;
int dp[]={}; int main()
{
int i,j;
int sgin=;
int n;
cin>>n;
for(i=;i<=n;i++){
j=;
sgin=;
while(j*j<=i){
if(dp[i-j*j]<sgin)
sgin=dp[i-j*j];
j++;
}
dp[i]=sgin+;
}
cout<<dp[n]<<endl;
return ;
}

ural 1073.Square Country(动态规划)的更多相关文章

  1. 01背包 URAL 1073 Square Country

    题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...

  2. ural 1073. Square Country

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

  3. Ural 1073 Square Country (DP)

    题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...

  4. URAL 1073 Square Country(DP)

    题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 ...

  5. ural 1698. Square Country 5(记忆化搜索)

    1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...

  6. URAL 1097 Square Country 2 离散化

    一共才100个正方形,将所有正方形左下角和右上角的X坐标和Y坐标离散化,直接枚举新建公园的点的坐标即可. O(n^3)的时间复杂度. #include <cstdio> #include ...

  7. URAL 1698. Square Country 5(记忆化搜索)

    题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...

  8. ural1097 Square Country 2

    Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...

  9. Square Country

    原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073 分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=mi ...

随机推荐

  1. HDU 5889 Barricade

    最短路,最小割,网络流. 可以根据$dis[u]+1$与$dis[v]$的大小关系判断$<u,v>$是否为最短路上的边,可以处理出一个只包含最短路的$DAG$,然后求这个$DAG$的最小割 ...

  2. NMON监控工具

    工具可将服务器的系统资源耗用情况收集起来并输出一个特定的文件,并可利用 excel 分析工具nmonanalyser进行数据的统计分析.并且,nmon运行不会占用过多的系统资源,通常情况下CPU利用率 ...

  3. google 技巧

    inurl: 用于搜索网页上包含的URL. 这个语法对寻找网页上的搜索,帮助之类的很有用. intext: 只搜索网页部分中包含的文字(也就是忽略了标题,URL等的文字). site: 可以限制你搜索 ...

  4. [SQL基础教程] 2-3 逻辑运算符

    [SQL基础教程] 2-3 逻辑运算符 NOT AND OR 优先级 ( )改变优先级 AND 优先级高于 OR NULL 引入三值逻辑

  5. c#语言简介

    语言的历史:c,c++,java,c#, c语言最早,c++语言复杂,而java把其中难的一部分去掉,也成为c--,而c#早期类似java. c#简单高效,并且与web结合. C#的运行环境是.net ...

  6. javabean+servlet+jsp实现分页

    前端实现用ligerUI实现分页,感觉用框架确实简单,闲着无聊,模拟着liger的分页界面实现了一遍(只要是功能,样式什么无视) 这里用基础的三层架构+servlet+jsp实现,思路很简单,把所有分 ...

  7. Hihocode 1015 KMP算法

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进. ...

  8. UNIX基础--安装应用程序: Packages 和 Ports

    Packages and Ports 概述 FreeBSD 将许多系统工具捆绑作为基本系统的一部分.另外,FreeBSD 提供了两种补充的技术来安装第三方软件:FreeBSD Ports Collec ...

  9. JAVA中方法的定义与使用(课堂学习归纳)

    组合数,百度词条是这样解释的:从m个不同元素中取出n(n≤m)个元素的所有组合的个数,叫做从m个不同元素中取出n个元素的组合数(Combination) 对于计算组合数,需要一定的工作量,计算机可以很 ...

  10. Python 函数之路

    ---恢复内容开始--- python函数的定义 def add(): a = 1 b = 2 c == a + b print(c) 函数就是把一段实现某一个功能的代放进一个封装的方法名里,这个方法 ...