求调
查看原帖
求调
1409258
wywzsq楼主2025/7/25 13:03

谁能告诉我:为什么相同的代码,在洛谷运行的结果和在devc++运行的结果不一样?

#include<bits/stdc++.h>
using namespace std;
const int maxn = 101;
int t, m, w[maxn], c[maxn], dp[maxn], ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t >> m;
	for(int i = 1; i <= m; i++)
		cin >> w[i] >> c[i];
	for(int i = 1; i <= m; i++)
	{
        //cout << w[i] << endl;
		for(int j = t; j >= w[i]; j--)
		{
		//cout << "j: " << j << " " << dp[j] << ' ';
			dp[j] = max(dp[j], dp[j - w[i]] + c[i]);
		//	cout << "j: " << j << " " << dp[j] << ' ';
        // cout << dp[j] << ' ';
		}
		//cout << endl;
	}
	cout << dp[t];
	return 0;
}

输入样例: 200 8 79 83 58 14 86 54 11 79 28 72 62 52 15 48 68 62

devc++输出:334

洛谷IDE输出:2241

标准答案:334

2025/7/25 13:03
加载中...