大佬们看看我的dfs为什么不对,
查看原帖
大佬们看看我的dfs为什么不对,
1106289
KomorKomor楼主2024/8/31 19:34
#include <bits/stdc++.h>  
#define ll long long  
using namespace std;  
vector<pair<int, int>> v(100);
ll res = -1e18, sum, m, x;
void dfs(ll money, int i)
{
    if(i == m)
    {
        res = max(res, sum);
        return ;
    }
    if(money >= v[i].first)
        sum += v[i].second, dfs(money - v[i].first + x, i + 1), sum -= v[i].second;
    else dfs(money + x, i + 1);
}
  
void solve() 
{  
    v.clear();  cin >> m >> x;
    for(int i = 0; i < m; i++)  cin >> v[i].first >> v[i].second;
    dfs(0, 0);
    cout << res << endl;
    res = -1e18, sum = 0;
}  
  
int main() 
{  
    ios::sync_with_stdio(false);  
    cin.tie(0); cout.tie(0);  
  
    int t = 1; cin >> t;  
    while (t--) solve();  
  
    return 0;  
}

先不管他会不会超时,但是为什么wa on test2了 大佬们教教

2024/8/31 19:34
加载中...