全部评论 66

  • d

    2025-02-22 来自 浙江

    3
  • 2025-02-22 来自 浙江

    3
  • 2024-12-14 来自 浙江

    3
  • 2024-12-14 来自 浙江

    3
  • 2024-12-14 来自 浙江

    3
  • @qi qpzc

    2025-02-22 来自 浙江

    2
  • 2024-12-14 来自 浙江

    2
  • #include<bits/stdc++.h>
    using namespace std;
    const int N=1e6+10;
    int a[N]{};
    int dp[N]{};
    vector<int>t[N];
    void dfs(int u,int fa){
        dp[u]=a[u];
        for(auto son:t[u]){
            if(son==fa)continue;
            dfs(son,u);
            if(dp[son]>0){
                dp[u]=dp[son]+dp[u];
            }
        }
        return;
    }
    int main(){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            t[u].push_back(v);
            t[v].push_back(u);
        }
        dfs(1,0);
        int ans=-0;
        for(int i=0;i<=n;i++)ans=max(ans,dp[i]);
        cout<<ans;
        return 0;
    }
    

    2025-05-24 来自 浙江

    1
  • #include <bits/stdc++.h>
    using namespace std;
    long long dp[2009];
    struct node{
        int w,c;
    };
    vector<node> ve[100009];
    int m,n,t;
    int main(){
        cin >> m >> n;
        for(int i = 0;i <= n;i++){
            int w,c,p;
            cin >> w >> c >> p;
            ve[p].push_back({w,c});    
        }
        for(int i = 1;i <= 100;i++){
            for(int j = m;j >=0;j--){
                for(int k = 0;k < ve[i].size();k++){
                    if(j >= ve[i][k].w) dp[j] = max(dp[j],dp[j - ve[i][k].w] + ve[i][k].c);
                }
            }
        }
        cout << dp[m];
    }
    

    2025-05-17 来自 浙江

    1
  • 本贴超过榜10了!!!!!

    2025-04-12 来自 浙江

    1
  • 3.15大根堆

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int n,m;
        cin >> n >> m;
        priority_queue<int> q;
        for(int i = 0;i < n;i++){
            int a,b,c;
            cin >> a >> b >> c;
            for(int j = 1;j <= m;j++){
                int tem = a * j * j + b * j + c;
                if(q.size() < m) q.push(tem);
                else if(q.top() > tem){
                    q.pop();
                    q.push(tem);
                }
                else break;
            }
        }
        vector<int> ve;
        while(q.size()){
            ve.push_back(q.top());
            q.pop();
        }
        for(int i = ve.size() - 1;i >= 0;i--) cout << ve[i] << ' ';
    }
    

    2025-03-15 来自 浙江

    1
  • 兄弟们,顶!

    2025-03-08 来自 浙江

    1
  • 2025-02-22 来自 浙江

    1
  • fd

    2025-02-22 来自 浙江

    1
  • d

    2025-02-22 来自 浙江

    1
  • d

    2025-02-22 来自 浙江

    1
  • d

    2025-02-22 来自 浙江

    1
  • d

    2025-02-22 来自 浙江

    1
  • 考古(

    4天前 来自 重庆

    0
  • 数学专题

    #include<bits/stdc++.h>
    using namespace std;
    const int N = 110;
    const double eps = 1e-8; 
    double a[N][N];
    int n;
    int gauss() { 
        int c = 0, r = 0;
        for (; c < n; c++) {
            int t = r;
            for (int i = r; i < n; i++) {
                if (fabs(a[i][c]) > fabs(a[t][c])) {
                    t = i;
                }
            }
            if (fabs(a[t][c]) < eps) continue;
            for (int i = c; i <= n; i++) {
                swap(a[t][i], a[r][i]);
            }
            for (int i = n; i >= c; i--) {
                a[r][i] /= a[r][c];
            }
            for (int i = r + 1; i < n; i++) {
                if (fabs(a[i][c]) > eps) {
                    for (int j = n; j >= c; j--) {
                        a[i][j] -= a[r][j] * a[i][c];
                    }
                }
            }
            r++;
        }
        if (r < n) {
            for (int i = r; i < n; i++) {
                if (fabs(a[i][n]) > eps) {
                    return 2;
                }
            }
            return 1;
        }
        for (int i = n - 1; i >= 0; i--) {
            for (int j = i + 1; j < n; j++) {
                a[i][n] -= a[i][j] * a[j][n];
            }
        }
        return 0;
    }
    
    int main() {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n + 1; j++) {
                scanf("%lf", &a[i][j]);
            }
        }
        int t = gauss();
        if (t == 0) {
            for (int i = 0; i < n; i++) {
                printf("%.2lf\n", fabs(a[i][n]) < eps ? 0.00 : a[i][n]);
            }
        } else if (t == 1) {
            cout << "Infinite group solutions";
        } else {
            cout << "No solution";
        }
        return 0;
    }
    

    4天前 来自 浙江

    0

热门讨论