poj1837

 Dynamic programing的本质是什么? 状态的转换。

#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
const int NUM=16000;
int dp[21][NUM];
int C[21];
int G[21];
int main()
{
	freopen("input.txt","r",stdin);
	int c,g;
	while(scanf("%d %d",&c,&g)!=EOF)
	{
		for(int i=1;i<=c;i++)
		{
			scanf("%d",&C[i]);
		}	
		for(int i=1;i<=g;i++)
		{
		scanf("%d",&G[i]);
		}
		memset(dp,0,sizeof(dp));
		dp[0][8000]=1;
		for(int i=1;i<=g;i++)
		{
			for(int j=500;j<=15500;j++)
			{
				for(int k=1;k<=c;k++)
				{
					int det=G[i]*C[k];
					dp[i][j]+=dp[i-1][j-det];
				}
			}
		}
		printf("%d\n",dp[g][8000]);
	}
	return 0;
}




你可能感兴趣的:(poj1837)