1 solutions

  • 1
    @ 2025-4-26 15:11:58
    #include <bits/stdc++.h>
    using namespace std;
    pair<int,int>g[201];
    int n,m,ans;
    void dfs(int dep,int w,int c);
    int main() {
    	scanf("%d%d",&m,&n);
    	for(int i = 1;i<=n;i++)scanf("%d%d",&g[i].first,&g[i].second);
    	dfs(1,0,0);
    	printf("%d",ans);
    	return 0;
    }
    void dfs(int dep,int w,int c){
    	if(w>m)return;
    	if(dep>n){
    		if(!w && !c)return;
    		ans = max(ans,c);
    		return;
    	}
    	dfs(dep+1,w,c);
    	dfs(dep+1,w+g[dep].first,c+g[dep].second);
    }
    
    • 1

    Information

    ID
    606
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    9
    Tags
    (None)
    # Submissions
    16
    Accepted
    4
    Uploaded By