能否幫我看一下程式哪裡出錯了? 謝謝
#include<iostream>
using namespace std;
int main()
{
long long t,n,p;
cin>>t;
while(t--){
cin>>n>>p;
long long w[p+1],dp[p+1][n+1]={0,0};
for(int i=1;i<=p;i++) cin>>w[i];
for(int i=1;i<=p;i++){
for(int j=1;j<=n;j++){
if(w[i]>j) dp[i][j]=dp[i-1][j];
else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+w[i]);
}
}
if(dp[p][n]==n) cout<<"YES\n";
else cout<<"NO\n";
}
}
//a522: 12455 - Bars
long long w[p+1],dp[p+1][n+1]={0,0};
dp不能這樣初始化