sgu160

DP

转移方程请自行脑补(或者看代码)

#include <ctime>
#include <cstdio>
#include <algorithm>
#define fly(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

inline int read()
{
    int x = 0, f = 1, t = getchar();
    while(t < 48 || t > 57) t == 45 ? f = -1 : 0, t = getchar();
    while(t > 47 && t < 58) x = (x << 1) + (x << 3) + t - 48, t = getchar();
    return x * f;
}

const int maxn = 10005;
const int maxm = 1005;
int n, m, a[maxn], f[maxn];
pair<int, int> from[maxn];

void write(int i)
{
    if(from[i].first) write(from[i].first);
    printf("%d ", from[i].second);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    register int i, j, k;
    n = read(), m = read();
    for(i = 1; i <= n; ++i) a[i] = read();
    for(i = 1; i <= n; ++i)
    {
        for(j = 1; j < m; ++j)
            if(f[j] && !f[k = j * a[i] % m] && from[j].second != i)
                f[k] = 1, from[k] = make_pair(j, i);
        if(!f[a[i]]) f[a[i]] = 1, from[a[i]] = make_pair(0, i);
    }
    for(int i = m-1; i >= 0; --i)
    {
        if(i == 0) puts("1");
        if(f[i])
        {
            printf("%d\n", i);
            write(i);
            break;
        }
    }

    fly("%.3f\n", (double)clock() / CLOCKS_PER_SEC);

#ifndef ONLINE_JUDGE
    fclose(stdin), fclose(stdout);
#endif
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值