原题链接: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. 如何停止AAD服务

    Connect-MsolService (Get-MSOLCompanyInformation).DirectorySynchronizationEnabled 用这个命令查看是enable还是Dis ...

  2. Ubuntu18.04重装指南

    Guide google chrome sougou 谷歌服务助手\(\rightarrow\)谷歌访问助手(谷歌应用商店)登录谷歌账号(cnyalitea@gmail.com)然后同步. \(\te ...

  3. 获取label标签内for的属性值-js

    <body> <div class="row_2" id="ass"> <label for="aaa"> ...

  4. 使用qemu启动dd制作的img镜像

    1. 准备工作 应用场景 在需要单机取证时,需要在不影响对象业务的情况下进行取证或分析,可以使用dd 对目标服务器进行镜像,生成img文件,镜像可以通过winhex进行静态分析.但是想要动态分析服务器 ...

  5. 《Linux内核与分析》第八周

    by 20135130王川东 一.进程切换关键代码switch-to分析     1.进程调度与进程调度时机分析 1)不同类型的进程有不同的调度要求 分类:I/0-bound:频繁的进行I/o 通常会 ...

  6. Java课程实验报告 实验四 Java网络编程及安全

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计     班级:1352     姓名:吕松鸿  学号:20135229 成绩:               ...

  7. PHP 函数总结

    感觉对函数了解的不够深,从头到尾梳理一遍(更新中....) 1,class_exists(),interface_exists(),method_exists(),get_class(),get_pa ...

  8. C++的反思与总结

    博客作业学到的东西: 1.博客作业应该说是从寒假就开始了,因为博客作业,所以我寒假时都不敢玩得太疯狂,毕竟还有博客作业没做呢.有了博客作业,我就从一个连博客是什么都不知道无知少年,开始去了解博客是什么 ...

  9. 未能加载文件或程序集 system.Web.Http.WebHost解决办法。

    在csdn中找到一个方法: Update-Package Microsoft.AspNet.WebApi -reinstall 然后就好了. 另外一个方法是缺少哪个dll,就复制一个dll放到bin文 ...

  10. Hibernate(六)

    三套查询之HQL查询 hql语句(面向):类   对象   属性 package com.rong.entity.hql; public class User { public User(int id ...