Loading

NOIP 模拟 $23\; \rm 题$

题解 \(by\;zj\varphi\)

考虑 \(\rm DP\)

\(dp_{k}(S)\) 表示前 \(k\) 个人来后 \(S\) 集合中的苹果都存在的概率是否大于 \(0\)

考虑倒着转移

\(\alpha.u_i,v_i\in S\)
\(\beta.u_i\in S,f_k(S\cup\{u_i\})=f_{k+1}(S)\)
\(\gamma.v_i\in S,f_k(S\cup\{v_i\})=f_{k+1}(S)\)
\(\delta.ui,vi∉S,f_k(S)=f_{k+1}(S)\)

最后要修改一些细节,看代码即可

Code
#include<bits/stdc++.h>
#define ri register signed
#define p(i) ++i
using namespace std;
namespace IO{
    char buf[1<<21],*p1=buf,*p2=buf; 
    #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++;
    template<typename T>inline void read(T &x){
	    ri f=1;x=0;register char ch=gc();
        while(ch<'0'||ch>'9'){if (ch=='-') f=0;ch=gc();} 
        while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=gc();} 
        x=f?x:-x;
    }
}
using IO::read;
namespace nanfeng{
    #define FI FILE *IN
    #define FO FILE *OUT
    template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
    template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
    static const int N=404,M=5e4+7;
    int bit[N][N],etn[N],n,m,ans;
    struct node{int a,b;}et[M];
    inline int main() {
        //FI=freopen("nanfeng.in","r",stdin);
        //FO=freopen("nanfeng.out","w",stdout);
        read(n),read(m);
        for (ri i(1);i<=m;p(i)) read(et[i].a),read(et[i].b);
        for (ri i(1);i<=n;p(i)) {
            bit[i][i]=1;
            for (ri j(m);j;--j) {
                if (bit[i][et[j].a]&&bit[i][et[j].b]) etn[i]=1;
                if (bit[i][et[j].a]||bit[i][et[j].b]) 
                    bit[i][et[j].a]=bit[i][et[j].b]=1;
            }
        }
        for (ri i(1);i<=n;p(i)) {
            if (etn[i]) continue;
            for (ri j(1);j<=n;p(j)) {
                if (etn[j]) continue;
                ri fg=1;
                for (ri k(1);k<=n;p(k)) if (bit[i][k]&&bit[j][k]) {fg=0;break;} 
                ans+=fg;
            }
        }
        printf("%d\n",ans>>1);
	    return 0;
    }
}
int main() {return nanfeng::main();}
posted @ 2021-07-25 19:15  ナンカエデ  阅读(53)  评论(2编辑  收藏  举报