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 ...
 
随机推荐
- Mate7微信指纹支付来了 比Touch ID整合微信早一点
			
之前我们聊过微信将推指纹支付 "指付通"会与Touch ID整合吗这个话题,现在有国内厂商率先支持微信指纹支付,体验一下美国用户使用Apple Pay搭配Touch ID来实现便捷 ...
 - hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)
			
Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
 - UIView中UIButton设置监听
			
红色框框是一个uibutton _priceValueLabel是他的父视图, 必须要把button的父视图设置userInteractionEnabled = YES, button的 监听才会生效 ...
 - Struts.xml讲解
			
解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...
 - neutron 中 flat vlan gre vxlan的区别
			
In a flat network, everyone shares the same network segment. For example, say 2 tenants are sharing ...
 - Product of Array Exclude Itself
			
Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WI ...
 - iOS 保存CGRect,CGPoint到NSArray'的方法
			
由于CGRect和CGPoint等对象是Struct,即结构体,不是继承于NSObject的,所以需要先用NSValue的方法,把他们转化成NSValue对象,之后就可以存入NSArray了! @in ...
 - canvas API ,通俗的canvas基础知识(四)
			
今天要讲的内容是canvas的转换功能,前面的内容没用看的同学可以出门右转,先看看前面的基础知识,废话不多说,开始进入正题吧! 何为转换功能?熟悉css3的同学都知道,css3里面有transform ...
 - DP:Making the Grade(POJ 3666)
			
聪明的修路方案 题目大意:就是农夫要修一条路,现在要求这条路要么就是上升的,要么就是下降的,总代价为∑|a[i]-b[i]|,求代价最低的修路方案, (0 ≤ β≤ 1,000,000,000) , ...
 - js简单上传进度条
			
效果如下: