sgu 160 分类: sgu 2015-04-22 19:51 43人阅读 评论(0) 收藏
记录每个数是否能生成[
及它是由如何是生成的。。。[
转移方程见代码,没加优化似乎
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define Mp(x,y) std::make_pair(x,y)
#define num first
#define si second
const int MAXN = 1e4+3, MAXM = 1e3+3;
typedef std::pair<int,int> FrNode;
int n, m, a[MAXN] = {0};
int f[MAXM] = {0};
FrNode fr[MAXM];
void DFS(int a)
{
if(fr[a].num) DFS(fr[a].num);
printf("%d ",fr[a].si);
}
int main()
{
bool flag = false;
#ifndef ONLINE_JUDGE
freopen("sgu160.in","r",stdin);
freopen("sgu160.out","w",stdout);
#endif
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
scanf("%d",a+i);
for(int i = 1; i <= n; i++)
{
for(int j = 1,k; j < m; j++)
if(f[j] && !f[k = j*a[i]%m] && fr[j].si != i)
f[k] = 1, fr[k] = Mp(j,i);
if(!f[a[i]]) f[a[i]] = 1, fr[a[i]] = Mp(0,i);
}
for(int i = m-1; i > 0; i--)
if(f[i]) {printf("%d\n",i),DFS(i); flag = true; break;}
if(!flag) puts("1");
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。