Ural 1073 Square Country

题意:要买n平方的土地,可以买的土地必须为某数的平方数,求至少要几块土地

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

思路:dp完全背包问题,状态转移方程dp[j] = min ( dp[j], dp[j-sq[i]] + 1 )

注意点:无


以下为AC代码:

IDDateAuthorProblemLanguageJudgement resultTest #Execution timeMemory used
6252988 12:45:29
18 May 2015
luminous111073. Square CountryG++ 4.9 C++11Accepted 0.031634 KB
/* 
***********************************************
*# @Author  : Luminous11 (573728051@qq.com)
*# @Date    : 2015-05-18 13:02:01
*# @Link    : http://blog.csdn.net/luminous11
*********************************************** 
*/

#include <bits/stdc++.h>
#define clr(a, v) memset( a , v , sizeof(a) )
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
int dp[60005];
int main()
{
	ios::sync_with_stdio ( false );
	int sq[300];
	for ( int i = 0; i < 300; i ++ ){
		sq[i] = i * i;
	}
	int n;
	while ( scanf ( "%d", &n ) != EOF ){
		memset ( dp, 0x3f3f3f3f, sizeof ( dp ) );
		dp[0] = 0;
		for ( int i = 1; i < 300; i ++ ){
			for ( int j = sq[i]; j <= n; j ++ ){
				dp[j] = min ( dp[j], dp[j-sq[i]] + 1 );
			}
		}
		printf ( "%d\n", dp[n] );
	}
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值