1.poj 1579
题目链接:
http://poj.org/problem?id=1579
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=1e4+5;
int a,b,c;
int vis[20][20][20];
int dp[20][20][20];
int solve(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)
{
return 1;
}
if(a>20||b>20||c>20)
{
return solve(20,20,20);
}
if(a<b&&b<c)
{
if(!vis[a][b][c])
{
dp[a][b][c]=solve(a,b,c-1)+solve(a,b-1,c-1)-solve(a,b-1,c);
vis[a][b][c]=1;
}
return dp[a][b][c];
}
else
{
if(!vis[a][b][c])
{
dp[a][b][c]=solve(a-1,b,c)+solve(a-1,b-1,c)+solve(a-1,b,c-1)-solve(a-1,b-1,c-1);
vis[a][b][c]=1;
}
return dp[a][b][c];
}
}
int main()
{
memset (vis,0,sizeof(vis));
while(scanf("%d%d%d",&a,&b,&c))
{
if(a==-1&&b==-1&&c==-1) break;
printf("w(%d, %d, %d) = %d\n",a,b,c,solve(a,b,c));
}
return 0;
}
2.hdu 1078 FatMouse and Cheese
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1078
dp[i][j]表示在i,j位置的最大数目.
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=105;
int n,k;
int a[maxn][maxn];
int vis[maxn][maxn];
int dp[maxn][maxn];
int pos[4][2]={
{0,1},{0,-1},{1,0},{-1,0}};
int ans;
int Max;
int M