ural 1073.Square Country(动态规划)
1073. Square Country
Memory limit: 64 MB
Input
Output
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(动态规划)的更多相关文章
- 01背包 URAL 1073 Square Country
题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...
- ural 1073. Square Country
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- Ural 1073 Square Country (DP)
题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...
- URAL 1073 Square Country(DP)
题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 ...
- ural 1698. Square Country 5(记忆化搜索)
1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...
- URAL 1097 Square Country 2 离散化
一共才100个正方形,将所有正方形左下角和右上角的X坐标和Y坐标离散化,直接枚举新建公园的点的坐标即可. O(n^3)的时间复杂度. #include <cstdio> #include ...
- URAL 1698. Square Country 5(记忆化搜索)
题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...
- ural1097 Square Country 2
Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...
- Square Country
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073 分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=mi ...
随机推荐
- 低功耗蓝牙BLE外围模式(peripheral)-使用BLE作为服务端
低功耗蓝牙BLE外围模式(peripheral)-使用BLE作为服务端 Android对外模模式(peripheral)的支持 从Android5.0开始才支持 关键术语和概念 以下是关键BLE术语和 ...
- Qt出现常量有换行符的错误的解决方法
可以使用 QString::fromLocal8Bit 来将本地字符编码转换为 Unicode 形式的 QString.
- SharpZipLib.dll 压缩文件,可以应用于MVC, webform. C# windows application 等等地方
Nuget 安装:Install-Package ICSharpCode.SharpZipLib.dll private void WriteZipFile(string[] filesToZip, ...
- Java的设计模式----strategy(策略模式)
设计模式: 一个程序员对设计模式的理解: “不懂”为什么要把很简单的东西搞得那么复杂.后来随着软件开发经验的增加才开始明白我所看到的“复杂”恰恰就是设计模式的精髓所在,我所理解的“简单”就是一把钥匙开 ...
- 查看Windows支持的内存大小
cmd命令: wmic memphysical get maxcapacity
- jsp中获取json字符串,并解析
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- JS禁用右键,禁用打印,防止另存为,IE浏览器识别(转载)
oncontextmenu="window.event.returnValue=false" style="overflow-y: hidden; overflow-x: ...
- incredibuild agent service is not running
incredibuild 不用介绍了,今天因为服务没有启动报错显示为: incredibuild agent service is not running 解决方法为: 在Incredibuild的安 ...
- 好用的meta标签
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> 保证中文在网 ...
- iOS 富文本点击事件
#import "ViewController.h" #define font 17 @interface ViewController ()<UITextViewDeleg ...