记录编号 571237 评测结果 AAAAAAAAAA
题目名称 [金陵中学2007] 最优分解方案 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 0.460 s
提交时间 2022-05-18 20:06:47 内存使用 2.50 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
typedef unsigned long long ull;
struct bigint {
    int g[100],len;
    bigint() {
        memset(g , 0 , sizeof(g));
        len = 1;
    }
    void print() {
        for(;len > 1&&!g[len];-- len);
        for(int i = len;i;-- i)printf("%d",g[i]);
        return ;
    }
    bigint operator = (int p) {
        len = 0;
        if(!p) {
            g[len = 1] = 0;
            return *this;
        }
        for(;p;p /= 10)g[++ len] = p % 10;
        return *this;
    }
    bool operator < (const bigint& p)const {
        if(len ^ p.len)return len < p.len;
        for(int i = len;i >= 1;-- i)
            if(g[i] ^ p.g[i])return g[i] < p.g[i];
        return false;
    }
    bool operator > (bigint p) {
        if(len ^ p.len)return len > p.len;
        for(int i = len;i;-- i)
            if(g[i] ^ p.g[i])return g[i] > p.g[i];
        return false;
    }
    friend bigint operator * (bigint a,int b) {
        bigint c;
        c.len = a.len;
        for(int i = 1;i <= c.len;++ i)c.g[i] = a.g[i] * b;
        for(int i = 1;i <= c.len;++ i)c.g[i + 1] += c.g[i] / 10,c.g[i] %= 10;
        for(;c.g[c.len + 1];++ c.len)c.g[c.len + 2] += c.g[c.len + 1] / 10,c.g[c.len + 1] %= 10;
        return c;
    }
};
bigint f[maxn];
bitset<maxn> s[maxn];
int n;
int main() {
    freopen("best.in","r",stdin);
    freopen("best.out","w",stdout);
    scanf("%d",&n);
    f[0] = 1;
    for(int i = 1;i <= n;++ i) {
        int id = 0;
        for(int j = 1;j <= i;++ j) {
            if(s[i - j].test(j))continue ;
            if(f[i - id] * id < f[i - j] * j)id = j;
        }
        if(!id)continue ;
        f[i] = f[i - id] * id;
        s[i] = s[i - id];
        s[i].set(id , 1);
    }
    f[n].print();
    return 0;
}