zoukankan      html  css  js  c++  java
  • P4306 [JSOI2010]连通数

    思路

    要求求每个点能到达的点数就是传递闭包
    然后n^3Floyd可做,但是n=2000,然后bitset压位
    复杂度(O(frac{n^3}{32})),能过

    代码

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <bitset>
    #include <string>
    #include <iostream>
    using namespace std;
    bitset<2010> S[2010];
    int n;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                char c=getchar();
                while(c!='0'&&c!='1')
                    c=getchar();
                if(i==j)
                    S[i][j-1]=1;
                else
                    S[i][j-1]=c-'0';
            }
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++){
                if(S[i][j-1])
                    S[i]|=S[j];
            }
        int ans=0;
        for(int i=1;i<=n;i++)
            ans+=(S[i].count());
        printf("%d
    ",ans);
        return 0;
    }
    
    /*
    3
    010
    001
    100
    
    9
    */
    
  • 相关阅读:
    日期时间插件
    QQ在线客服
    dede轮播图
    Animation 案例解释
    transition Css3过度详解
    解决文字无法缩小的问题
    DEDE函数
    hdu 3435 图回路分割
    HDU 4183
    hdu 1569 最小割
  • 原文地址:https://www.cnblogs.com/dreagonm/p/10496098.html
Copyright © 2011-2022 走看看