求调代码!样例过不了!(急)给关注!
查看原帖
求调代码!样例过不了!(急)给关注!
494699
卷王慢即快楼主2022/11/16 20:11
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int a[11];
int t[11], cnt = 1;
int mp[11][11];
int c = 0, Ans[11];
inline void work(int x)
{
    cout << 1 << endl; //16
    ans += a[x];
    for(int i = x + 1; i <= n; i++)
        if(mp[x][i])
        {
            t[++cnt] = i;
            work(i);
        }
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n - 1; i++)
        for(int j = i + 1; j <= n; j++)
        {
            cin >> mp[i][j];
            mp[j][i] = mp[i][j];
        }
    for(int i = 1; i <= n; i++)
    {
        memset(t, 0, sizeof(t));
        t[1] = 1;
        cnt = 1;
        ans = 0;
        work(i);
        if(ans > c)
        {
            c = ans;
            Ans[1] = i;
            for(int j = 2; j <= cnt; j++)
                Ans[j] = t[j];
        }
    }
    for(int i = 1; i <= cnt; i++)
        cout << Ans[i] << " ";
    cout << endl << ans;
    return 0;
}
2022/11/16 20:11
加载中...