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 ...
随机推荐
- HNU 12826 Balloons Colors
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12826&courseid=268 #include&l ...
- index and polymorphic
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations class CreateStars < ...
- git参考资料
个人博客 http://www.iwangzheng.com/ $git log --graph $git reset --hard 67889898... $ssh-add $git pull -- ...
- [POJ1003]Hangover
[POJ1003]Hangover 试题描述 How far can you make a stack of cards overhang a table? If you have one card, ...
- [BZOJ1163][BZOJ1339][Baltic2008]Mafia
[BZOJ1163][BZOJ1339][Baltic2008]Mafia 试题描述 匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用 ...
- PHP 遍历目录
$dir = $_SERVER['DOCUMENT_ROOT'].'/test'; //var_dump($dir);exit; function my_scandir($dir) { $files ...
- raw格式镜像文件压缩并转换为qcow2格式
raw格式文件,这个比较占用空间,你可以用以下命令将其压缩并转换成qcow2格式. # virt-sparsify --compress --convert qcow2 ubuntu.img ubun ...
- catalog、scheme区别
按照SQL标准的解释,在SQL环境下Catalog和Schema都属于抽象概念,可以把它们理解为一个容器或者数据库对象命名空间中的一个层次,主要用来解决命名冲突问题.从概念上说,一个数据库系统包含多个 ...
- 《转》常用Petri网模拟软件工具简介
本文转载自liusj2003,如给您带来不便之处,请联系博主. 首先要介绍的的一个非常有名的Petri 网网站--Petri Nets World: http://www.informatik.uni ...
- 1.2 中国象棋将帅问题进一步讨论与扩展:如何用1个变量实现N重循环?[chinese chess]
[题目] 假设在中国象棋中只剩下将帅两个棋子,国人都知道基本规则:将帅不能出九宫格,只能上下左右移动,不能斜向移动,同时将帅不能照面.问在这样条件下,所有可能将帅位置.要求在代码中只能使用一个字节存储 ...