hdu 1978 简单dp

其实就是枚举当前点,然后枚举可以到打的点,将初始点初始为1,然后每个可到达的点加上当前点的可到达数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int dp[107][107];
int a[107][107];

int main ( )
{
    int t,n,m;
    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" , &a[i][j] );
        memset ( dp , 0 , sizeof ( dp ) );
        dp[1][1] = 1;
        for ( int i = 1 ; i <= n ; i++ )
            for ( int j = 1 ; j <= m ; j++ )
                for ( int k = 0 ; k <= a[i][j] ; k++ )
                    for ( int t = 0 ; t <= a[i][j] - k ; t++ )
                    {
                        if ( k == t && k == 0 ) continue;
                        if ( i + k > n ) continue;
                        if ( j + t > m ) continue;
                        dp[i+k][j+t] += dp[i][j];
                        dp[i+k][j+t] %= 10000;
                    }
        printf ( "%d\n" , dp[n][m] );
    }
}


你可能感兴趣的:(C++,动态规划)