求助
查看原帖
求助
1334291
huyu123楼主2025/7/20 17:12

这个做法为什么不对:用dp[i][j][k]表示走到点(i,j)花费k元的方案数.

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=48,M=998244353;
ll dp[N][N][200],n,m,k,a[N][N],b[N][N];
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%lld",&a[i][j]);
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%lld",&b[i][j]);
        }
    }
    dp[1][1][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<dp[i][j][k]<<' ';
            for(int t=0;t<=k;t++)
            {
                for(int x=1;x+i<=n&&a[i][j]*x+t<=k;x++)
                {
                    dp[i+x][j][t+a[i][j]*x]+=dp[i][j][t];
                    dp[i+x][j][t+a[i][j]*x]%=M;
                }
                for(int x=1;x+j<=m&&b[i][j]*x+t<=k;x++)
                {
                    dp[i][j+x][t+b[i][j]*x]+=dp[i][j][t];
                    dp[i][j+x][t+b[i][j]*x]%=M;
                }
            }
        }
        cout<<'\n';
    }
    return 0;
}
2025/7/20 17:12
加载中...