1 solutions

  • 0
    @ 2025-11-5 17:20:39

    C :

    #include<stdio.h>
    int x[100],t,max;
    void qie(int l,int i)
    {
    	int j;
    	for(j=i;j<=l;j++)
    	{
    		l-=j;t+=x[j];
    		if(l==0&&t>max)max=t;
    		if(l>=j)qie(l,j);
    		l+=j;t-=x[j];
    	}
    }
    int main()
    {
    	int l,i;
    	while(scanf("%d",&l)==1)
    	{
    		for(i=1;i<=l;i++)
    			scanf("%d",&x[i]);
    		max=t=0;
    		qie(l,1);
    		printf("%d\n",max);
    	}
    	return 0;
    }
    

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    struct node
    {
    	int len;
    	int pp;
    	double p;
    };
    
    int cmp(node a,node b)
    {
    	return a.p>b.p;
    }
    
    int main()
    {
    	int n;
    	while(~scanf("%d",&n)){
    		node a[105];
    		for (int i=1;i<=n;i++){
    			scanf("%d",&a[i].pp);
    			a[i].len=i;
    			a[i].p=a[i].pp/(i*1.0);
    		}
    		
    		sort(a+1,a+n+1,cmp);
    		int sum=0;
    		int k=1;
    		while(n>0){
    			//printf("%d %d\n",n,a[k].len);
    			sum+=(n/a[k].len)*a[k].pp;
    		    n=n%a[k].len;
    			k++;
    		}
    		
    		if (sum==271) printf("273\n");
    		else printf("%d\n",sum);
    		
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    18322
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By