4809 江哥的dp题c

4809 江哥的dp题c

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 Description

有两个数x,y,一开始x=1,y=1.现给定一个参数N和一个数组p(p1,p2,p3,……,pN),你需要按以下规则操作:

若x≤N,则你需要选择一个正整数k,然后将x变为kx,将y变成y*px。

当x>N时,结束操作,你的得分即为y的值,求最大得分。 

输入描述 Input Description

第一行一个正整数N。

接下来一行N个正整数,描述p。

输出描述 Output Description

输出一行一个整数,描述答案。

样例输入 Sample Input

10

1 2 3 4 5 6 7 8 9 10

样例输出 Sample Output

 

64

数据范围及提示 Data Size & Hint

k为你自己选定的一个定值。

测试点编号        数据范围

1,2,3                   N≤15

4,5,6,7              N≤50000

8,9,10               N≤10^6

分类标签 Tags 点此展开 

AC代码:

#include<cstdio>
#include<cmath>
#include<iostream>
#include<iomanip>
#define ll long long
using namespace std;
inline const int read(){
    register int x=0,f=1;
    register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
const int N=1e6+1;
ll p[N/100];
double dp[N];
int n,a[N],t[N];
int s=1,cnt=1;
int main(){
    n=read();p[1]=1;
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=n;i;i--){
        for(int j=i;j<=n;j+=i){
            if(dp[i]<dp[j]) dp[i]=dp[j],t[i]=j;
        }
        dp[i]+=log(a[i]);
    }
    for(;s;s=t[s]){
        for(int i=1;i<=cnt;i++) p[i]*=(ll)a[s];
        for(int i=1;i<=cnt||p[i];i++){//高精度压位 
            p[i+1]+=p[i]/100000,p[i]%=100000,cnt=max(cnt,i);
        }
    }
    cout<<p[cnt];
    for(int i=cnt-1;i;i--) cout<<setfill('0')<<setw(5)<<p[i];
    return 0;
}

 

posted @ 2016-11-08 16:43  神犇(shenben)  阅读(121)  评论(0编辑  收藏  举报