原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073

分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=min(i,dp[i-j*j]+1)(1<=j<=sqrt(i)).

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#define ll long long
#define maxn 60005
using namespace std;
int dp[maxn];
void solve()
{
memset(dp,0,sizeof(dp));
dp[0]=0;dp[1]=1;dp[2]=2;dp[3]=3;dp[4]=1;
for(int i=5;i<=60000;i++)
{
dp[i]=i;
for(int j=1;j*j<=i;j++)
dp[i]=min(dp[i],dp[i-j*j]+1);
}
}
int main()
{
int n;
solve();
cin>>n;
cout<<dp[n]<<endl;
return 0;
}

Square Country的更多相关文章

  1. ural 1073. Square Country

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

  2. 01背包 URAL 1073 Square Country

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

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

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

  4. ural 1073.Square Country(动态规划)

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

  5. ural1097 Square Country 2

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

  6. URAL 1097 Square Country 2 离散化

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

  7. URAL 1073 Square Country(DP)

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

  8. Ural 1073 Square Country (DP)

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

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

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

随机推荐

  1. Cesium开发添加entity无法显示

    无代码报错,js查询entity数量发现确实添加进去了.但是在底图上就是不显示. 有可能是跨域产生的问题.打开开发者工具Console栏.查看是不是存在跨域错误. 解决跨域后entity正常加载.

  2. 建立 Python 虚拟环境

    1.1 安装依赖包 $ yum -y install wget gcc epel-release git 1.2 安装 Python3.6和pip $ yum -y install python36 ...

  3. python format用法详解

    #常用方法:print('{0},{1}'.format('zhangk', 32)) print('{},{},{}'.format('zhangk','boy',32)) print('{name ...

  4. activemq 持久化

    转自: http://blog.csdn.net/kobejayandy/article/details/50736479 消息持久性的原理很简单,就是在发送者将消息发送出去后,消息中心首先将消息存储 ...

  5. 复利计算器app发布

    复利计算器app发布 抱歉:由于无法实现服务端的持续开启,发布的app仅为简单的单机版,暂时舍弃了c/s版本的一些功能,如:投资动态管理功能. 应用详情博客:请点击这里 apk下载地址1(百度手机助手 ...

  6. TensorFlow:NameError: name ‘input_data’ is not defined

    在运行TensorFlow的MNIST实例时,第一步 import tensorflow.examples.tutorials.mnist.input_data mnist = input_data. ...

  7. 【最小生成树+LCA】Imperial roads

    http://codeforces.com/gym/101889 I 先跑一遍最小生成树,把经过的边和答案记录下来 对于每个询问的边,显然如果处于MST中,答案不变 如果不在MST中,假设这条边连上了 ...

  8. Java中的网络编程-2

    Socket编程:(一般的网络编程) <1> 两个 JAVA 应用程序可通过一个双向的网络通信连接, 实现数据交换, 这个双向链路的一段称为一个 Socket. <2> Soc ...

  9. lintcode-422-最后一个单词的长度

    422-最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 注意事项 一个单词的界定是,由字母组成,但不包含任何的空 ...

  10. IBM存储降级告警等一些服务器问题/dd/ethtool

    1.IBM存储降级告警 一般两种情况 a.端口降级 例如模块16G->8G(IBM储存端口自适应) b.系统在作raid后,有硬盘损坏,降级 黄灯告警 2. dimm error dimm内存插 ...