1 solutions

  • 0
    @ 2025-11-5 17:24:53

    C++ :

    #include <stdio.h>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <map>
    #include <string.h>
    using namespace std;
    int dp[1005];
    int max(int a,int b)
    {
    	if(a>b)
    		return a;
    	else
    		return b;
    }
    int main()
    {
    	 dp[1]=1;
    	 dp[2]=2;
    	 dp[3]=3;
    	 dp[4]=4;
    	 dp[5]=6;
    	 int i,j;
    	 int maxa=-1;
    	 for( i=6;i<=1000;i++)
    		 for( j=1;j<i;j++)
    		 {
    			 maxa=max(maxa,dp[j]*(i-j));
    			 dp[i]=maxa;
    		 }
         int n;
    	 while(scanf("%d",&n)!=EOF)
    	 {
    		 if(n==0)
    			 break;
    		 printf("%d\n",dp[n]);
    	 }
    	 return 0;
    }
    
    • 1

    Information

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