全部评论 64

  • 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
  • #include<bits/stdc++.h>
    using namespace std;
    int to[8][2]={-2,1,-1,2,1,2,2,1,1,-2,2,-1,-1,-2,-2,-1};
    bool vis[209][209];
    int n,m;
    string mp[209];
    int bx,by,ex,ey;
    struct node{
    	int x,y;
    	int step;
    };
    queue<node>q;
    void bfs(){
    	node u,v;
    	u.x=bx,u.y=by,u.step=0;
    	vis[bx][by]=true;
    	q.push(u);
    	while(!q.empty()){
    		u=q.front();
    		q.pop();
    		if(u.x==ex&&u.y==ey){
    			cout<<u.step;
    			return;
    		}
    		for(int i=1;i<8;i++){
    			v.x=u.x+to[i][0];
    			v.y=u.y+to[i][1];
    			v.step=u.step+1;
    			if(v.x>=0&&v.x<n&&v.y<m&&vis[v.x][v.y]==false&&mp[v.x][v.y]!='*'){
    				vis[v.x][v.y]=true;
    				q.push(v);
    			}
    		}
    	}
    }
    int main(){
    	cin>>m>>n;
    	for(int i=0;i<n;i++){
    		cin>>mp[i;]
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			if(mp[i][j]=='K'){
    				bx=i;
    				by=j;
    			}
    			if(mp[i][j]='H'){
    				ex=i;
    				ey=j;
    			}
    		}
    	}
    	bfs();
    	return 0;
    }
    

    18小时前 来自 浙江

    0
  • 5.31贪心

    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    struct Hero {
        int dps;
        int hp;
    };
    
    bool compare(const Hero &a, const Hero &b) {
        return a.dps * b.hp > b.dps * a.hp;
    }
    
    int main() {
        int n;
        cin >> n;
        vector<Hero> heroes(n);
        
        for (int i = 0; i < n; ++i) {
            cin >> heroes[i].dps >> heroes[i].hp;
        }
        
        sort(heroes.begin(), heroes.end(), compare);
        
        int total_dps = 0;
        for (const auto &h : heroes) {
            total_dps += h.dps;
        }
        
        int damage = 0;
        for (const auto &h : heroes) {
            damage += total_dps * h.hp;
            total_dps -= h.dps;
        }
        
        cout << damage << endl;
        return 0;
    }
    

    2025-05-31 来自 浙江

    0

热门讨论