P2150 [NOI2015] sushi dinner

https://www.luogu.com.cn/problem/P2150

answer

Before the number (except 1) n assigned to two head groups must be coprime.

Consider only 30% prime shape 10 can be press-F [i] [j] indicates a state where a first group of prime number i, j of the second group have a good number of ways.

显然f[i][j&s]+=f[i][j](!(i&s))

f[i&s][j]+=f[i][j](!(j&s))

f[0][0]=1;

Consider 100%

Found 500 open within 2222 with only eight prime, and prime number over 22 can not have two of the same number of qualifying years. We remember that each number of small primes state s, large prime numbers da.

All the same, right row of large prime numbers together to ensure that such a large prime number is only a single candidate.

Transfer with three arrays

code show as below:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=505;
int n,mo,f1[N][N],f2[N][N],dp[N][N],zhi[10]={1,2,3,5,7,11,13,17,19};
struct pigu
{
    you da, s;
}a[N];
inline int read()
{
    char c=getchar();
    int x=0,f=1;
    while(!isdigit(c)) {if(c=='-') f=-1;c=getchar();}
    while(isdigit(c)) {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*f;
}
inline int add(int x,int y)
{
    return x + y> mo-mo x + y: x +? y;
}
Inline screw CMP (pigu x, y pigu)
{
    return x.da<y.da;
}
signed main()
{
    n=read();mo=read();
    if(mo==1)
    {
        cout<<"0";
        return 0;
    }
    for(int i=2;i<=n;i++)
    {
        int hu=i;
        for(int j=1;j<=8;j++)
        {
            while(hu%zhi[j]==0)
            {
                Hu / = Zhi [J];
                a[i].s|=(1<<j-1);
            }
        }    
        if (hu! = 1 ) and [i] = .da hu;
    }
    dp[0][0]=1;
    sort(a+2,a+n+1,cmp);
    for(int i=2;i<=n;i++)
    {
        if(a[i].da!=a[i-1].da||a[i].da==0)
        {
            for(int j=0;j<=255;j++) 
                for(int k=0;k<=255;k++)
                    f1[j][k]=f2[j][k]=dp[j][k];
        }
        for(int j=255;j>=0;j--)
            for(int k=255;k>=0;k--)
                if(!(j&k))
                {
                    if(!(j&a[i].s)) f2[j][k|a[i].s]=add(f2[j][k|a[i].s],f2[j][k]);
                    if(!(k&a[i].s)) f1[j|a[i].s][k]=add(f1[j|a[i].s][k],f1[j][k]);
                }
        if(a[i].da!=a[i+1].da||a[i].da==0||i==n)
        {
            for(int j=0;j<=255;j++)
                for(int k=0;k<=255;k++)
                    if(!(j&k))
                    {
                        dp[j][k]=add(mo-dp[j][k],add(f1[j][k],f2[j][k]));
                    }
        }
    }
    int ans=0;
    for(int i=0;i<=255;i++) for(int j=0;j<=255;j++) if(!(i&j))ans=add(ans,dp[i][j]);
    cout << years;
}
View Code

 

Guess you like

Origin www.cnblogs.com/betablewaloot/p/12339756.html