在做一个0-1背包最基本的题的时候居然运行错了:
#include <iostream>
using namespace std;
int dp[1005]; //dp表格
int w[105], c[105];
int main()
{
int n, m; //容量,物品数目
cin >> n >> m; //物品占容,物品价值
for (int i = 1; i <= n; i++)
{
cin >> w[i] >> c[i];
}
for (int i = 1; i <= m; i++)
{
for (int j = n; j >= w[i]; j--)
{
dp[j] = max(dp[j], dp[j - w[i]] + c[i]);
}
}
// int ans = dp[n];
cout << dp[n];
return 0;
}
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
Runtime Error:Segmentation fault
这是怎么回事