Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

hdu 1978

$
0
0

dp




#include<stdio.h>
int map[110][110],dp[110][110];
int main()
{
	int t,n,m,i,j,sum,k,p;
    scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++)
			for(j=0;j<m;j++)
			{
				scanf("%d",&map[i][j]);
				dp[i][j]=0;
			}
			dp[0][0]=1;
			for(i=0;i<n;i++)
				for(j=0;j<m;j++)
				{
					sum=map[i][j];
					dp[i][j]=dp[i][j]%10000; 
				        for(k=0;k<=sum&&k+i<n;k++)
							for(p=0;p+k<=sum&&p+j<m;p++)
							{
								if(k==0&&p==0)continue;
								dp[k+i][p+j]=dp[k+i][p+j]+dp[i][j];
							}
				}
				printf("%d\n",dp[n-1][m-1]);
	}
	return 0;
}


作者:aixiaoling1314 发表于2013-5-6 21:18:43 原文链接
阅读:51 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>