动态规划-FATE

本文展示了一个使用C++实现的动态规划算法示例,该算法用于解决特定问题,通过定义状态转移方程来求解最优解。文章通过具体的代码实现了动态规划过程,并通过输入输出数据来验证算法的有效性。

#include <stdio.h>
using namespace std;
#define min(x,y) (x<y)?x:y
#define INF 0x7fffffff
int a[110];
int b[110];
int dp[110][110];
int main()
{
	int n,m,k,s,i,j,a,b,l,ans;
	while(~scanf("%d %d %d %d",&n,&m,&k,&s))
	{
		for(i=0;i<110;i++)
			for(j=0;j<110;j++)
				dp[i][j]=INF;
		for(i=1;i<=k;i++)
			scanf("%d%d",&a[i],&b[i]);
		ans=0;
		for(i=1;i<=m;i++)
		{
			for(j=1;j<=k;i++)
			{
				for(l=1;l<=s;l++)
					if(i>=b[j]])
						dp[i][l]=min(dp[i][l],dp[i-b[j]][l-1]+a[j]);
				if(dp[i][s]>=n)
				{
					ans=m-i;
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
} 

ogging to D:\Program Files (x86)\Fate/hollow ataraxia\FateFD.exe.console.log started on Friday, October 07, 2011 12:48:08 12:48:07 ! (info) Loading options from embedded area... 12:48:07 ! 吉里吉里[きりきり] 2 実行コア/2.25.11.909 (SVN revision:1109; Compiled on Sep 12 2005 22:44:16) TJS2/2.4.19 Copyright (C) 1997-2005 W.Dee and contributors All rights reserved. 12:48:07 ! バージョン情報の詳細は Ctrl + F12 で閲覧できます 12:48:07 ! Program started on Windows NT 6.1.3505 Service Pack 1 (Win32) 12:48:07 ! (info) Total physical memory : -1 12:48:07 ! (info) Selected project directory : file://./d/program files (x86)/fate/hollow ataraxia/data.xp3> 12:48:07 ! (info) CPU #0 : FPU:yes MMX:yes 3DN:no SSE:yes CMOVcc:yes E3DN:no EMMX:yes SSE2:yes TSC:yes Intel(GenuineIntel) [Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz] CPUID(1)/EAX=00020652 CPUID(1)/EBX=00100800 12:48:07 ! (info) CPU #1 : FPU:yes MMX:yes 3DN:no SSE:yes CMOVcc:yes E3DN:no EMMX:yes SSE2:yes TSC:yes Intel(GenuineIntel) [Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz] CPUID(1)/EAX=00020652 CPUID(1)/EBX=01100800 12:48:07 ! (info) CPU #2 : FPU:yes MMX:yes 3DN:no SSE:yes CMOVcc:yes E3DN:no EMMX:yes SSE2:yes TSC:yes Intel(GenuineIntel) [Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz] CPUID(1)/EAX=00020652 CPUID(1)/EBX=04100800 12:48:07 ! (info) CPU #3 : FPU:yes MMX:yes 3DN:no SSE:yes CMOVcc:yes E3DN:no EMMX:yes SSE2:yes TSC:yes Intel(GenuineIntel) [Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz] CPUID(1)/EAX=00020652 CPUID(1)/EBX=05100800 12:48:07 ! (info) finally detected CPU features : FPU:yes MMX:yes 3DN:no SSE:yes CMOVcc:yes E3DN:no EMMX:yes SSE2:yes TSC:yes 12:48:07 ! (info) Specified option(s) : -debugwin=no 12:48:07 ! (info) Loading cxdec.tpm 12:48:08 ! OS : Windows NT 6.1.3505 Service Pack 1 (Win32) 12:48:08 ! KAG : 3.25 beta 10 TYPE-MOON customized 12:48:08 ! Kirikiri : 2.25.11.909
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值