您的位置:首页 > 其它

Hdu 1978 How many ways 二维dp水题。。

2015-09-09 14:58 381 查看
嗯题目是中文多琢磨就懂了就不解释了。

我只是来水一发题解。。 直接两层循环, 遍历每个点然后对于每个点将从这个点出发可达的每个点的方法数都再加上这个点的方法数,随便水一水就过了。。

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 105 ;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;
int n,m,mp[maxn][maxn];
int dp[maxn][maxn];
int main () {
#ifdef LOCAL
	freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//      freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
#endif
    int T;
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d",&n,&m);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                scanf("%d",&mp[i][j]);
        CLR(dp);
        dp[1][1] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                int d = mp[i][j];
                for (int dx = 0; dx <= d; dx++) {
                    if (i + dx > n) break;
                    for (int dy = 0; dy + dx <= d; dy++) {
                        if (j + dy > m) break ;
                        if (dx==0&&dy==0) continue ;
                        dp[i+dx][j+dy] = (dp[i][j] + dp[i+dx][j+dy]) % 10000 ;
                    }
                }
            }
        }
        cout << dp[n][m] << "\n" ;
    }
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: