Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

ms都是递归的...贴个非递归的dp

Posted by intheway at 2009-11-27 18:26:57 on Problem 1664
#include <iostream>
using namespace std;
const int MAXN = 11;
int f[MAXN][MAXN];//苹果数, 盘子数 

int dp(int n, int m){
	if(n > m)	n = m;
	int i, j;
	for(i = 0; i <= m; ++i)
		f[i][1] = 1;
	for(j = 0; j <= n; ++j)
		f[0][j] = 1;
	for(i = 1; i <= m; ++i)
		for(j = 2; j <= n; ++j){
			f[i][j] = f[i][j-1];
			if(i >= j)
				f[i][j] += f[i-j][j];
		}
	return f[m][n];
}
	
int main(){
	int T, n, m;
	scanf("%d", &T);
	while(T--){
		scanf("%d%d", &m, &n);
		printf("%d\n", dp(n, m));
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator