The maximum approximate sum of Luogu P1734 and Luogu p1734

Source: Internet
Author: User

The maximum approximate sum of Luogu P1734 and Luogu p1734
Description

Select a number of different positive integers that do not exceed S, so that the sum of all values (excluding itself) is the maximum.

Input/Output Format

Input Format:

 

Enter a positive integer (S.

 

Output Format:

 

The sum of the largest divisor output.

 

Input and Output sample input sample #1: Copy
11
Output example #1: Copy
9
Description

Example

Take the numbers 4 and 6 to obtain the maximum value (1 + 2) + (1 + 2 + 3) = 9.

Data Scale

S<=1000




Think of the approximate number of each item as the weight and the value as the weight.


 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 const int MAXN=1001; 5 inline char nc() 6 { 7     static char buf[MAXN],*p1=buf,*p2=buf; 8     return p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXN,stdin),p1==p2)?EOF:*p1++; 9 }10 inline int read()11 {12     char c=nc();int x=0,f=1;13     while(c<'0'||c>'9'){if(c=='-')f=-1;c=nc();}14     while(c>='0'&&c<='9'){x=x*10+c-'0';c=nc();}15     return x*f;16 }17 inline int work(int x)18 {19     int ans=0;20     for(int i=1;i<x;i++)   21         if(x%i==0)  ans+=i;22     return ans;23 }24 struct node25 {26     int val,w;27 }a[MAXN];28 int dp[MAXN];29 int main()30 {31     #ifdef WIN3232     freopen("a.in","r",stdin);33     #else34     #endif35     int n=read();36     for(int i=1;i<=n;i++)   a[i].val=work(i),a[i].w=i;37     for(int i=1;i<=n;i++)38         for(int j=n;j>=a[i].w;j--)39             dp[j]=max(dp[j],dp[j-a[i].w]+a[i].val);40     printf("%d",dp[n]);41 } 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.