01背包 URAL 1073 Square Country
/*
题意:问n最少能是几个数的平方和
01背包:j*j的土地买不买的问题
详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2200721.html
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std; const int MAXN = 6e4 + ;
const int INF = 0x3f3f3f3f;
int dp[MAXN]; int main(void) //URAL 1073 Square Country
{
//freopen ("I.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
memset (dp, , sizeof (dp));
for (int i=; i<=n; ++i)
{
dp[i] = dp[i-] + ;
for (int j=; j<=sqrt (n*1.0); ++j)
{
if (i >= j * j) dp[i] = min (dp[i], dp[i-j*j] + );
else break;
}
} printf ("%d\n", dp[n]);
} return ;
}
01背包 URAL 1073 Square Country的更多相关文章
- 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(动态规划)
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位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...
- Proud Merchants(01背包)
Proud Merchants Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- Temple Build~dp(01背包的变形)
The Dwarves of Middle Earth are renowned for their delving and smithy ability, but they are also mas ...
随机推荐
- FineUI第七天---文件上传
文件上传的方式: 控件的一些常用属性: ButtonText:按钮文本. ButtonOnly:是否只显示按钮,不显示只读输入框. ButtonIcon:按钮图标. ButtonIconUrl: ...
- 淘宝(阿里百川)手机客户端开发日记第八篇 Handler的使用方法
首先,我们先看下API文档的说明: A Handler allows you to send and process Message and Runnable objects associated w ...
- nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
iwangzheng.com tty:[0] jobs:[0] cwd:[/opt/nginx/conf] 12:45 [root@a02.cmsapi]$ /usr/local/nginx/sbin ...
- Cocos2d坐标系转换
Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...
- ubuntu 快速安装jre
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-i ...
- 减小Delphi XE5编译出来的程序体积
默认Delphi XE, XE2, XE3,XE4,XE5, XE6 ... 编译出来的程序体积很大. 一般用两个方法可以很大程度上减少程序体积. 一.在工程中用编译指令禁用RTTI 禁用的方法很简单 ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Linux rpm安装问题解决
1.安装时提示:warning: *.rpm: Header V3 RSA/SHA256 Signature, keykey ID c105b9de: NOKEY 解决的方法就是在rpm 语句后面加上 ...
- Linux Apache和Nginx的比较
1.nginx相对于apache的优点: 轻量级,同样起web 服务,比apache占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx ...
- 用Python操纵MySQL
本例用Python操纵MySQL,从指定文件读取数据,并对数据进行处理,处理之后批量插入MySQL. 贴上代码: # -*- coding: gbk -*- import re import MySQ ...