随笔分类 - 枚举
摘要:给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量。输入格式第一行两个整数N,M,接下来M行每行两个整数x,y,表示从x到y的一条有向边。输出格式输出共N行,表示每个点能够到达的点的数量。数据范围1≤N,M≤30000<?XML:NAMESPACE PREFIX = "[def
        阅读全文
            
摘要:小明被绑架到X星球的巫师W那里。其时,W正在玩弄两组数据 (2 3 5 8) 和 (1 4 6 7)他命令小明从一组数据中分别取数与另一组中的数配对,共配成4对(组中的每个数必被用到)。小明的配法是:{(8,7),(5,6),(3,4),(2,1)}。巫师凝视片刻,突然说这个配法太棒了!因为:每个配
        阅读全文
            
摘要:看到这题就知道要暴力枚举,然后就用二进制枚举,用整数来表示对应十字架的状态,也就是2的幂次。 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <vector> 5 using namespace
        阅读全文
            
摘要:枚举正方行边长为r的 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 const int N = 5e3 + 5; 7 int g[N][N]; 8 int ma
        阅读全文
            
摘要:由题可得: 1.每个等最多点一次 2.当第一行固定,最多由一种结果,每一行的状态,要由下一行转换过来。所以枚举第一行的状态,来计算答案 #include <iostream> #include <algorithm> #include <cstring> using namespace std; c
        阅读全文
            
摘要:运用二进制状态压缩,模板题 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 6 int f[1 << 20][20], weight[20][20], n;//f[i
        阅读全文
            
摘要:1 #include <bits/stdc++.h> 2 using namespace std; 3 constexpr size_t maxn = 105; 4 int dx[9]={1,0,1,-1,0,-1,1,-1};//八个方位 5 int dy[9]={0,1,1,0,-1,-1,-1
        阅读全文
            
摘要:先看题吧我猜到多数人开始想的就是二进制暴力枚举,对吧,这题这样做可以因为只需要提交答案,完全可以本地暴力,1e9的数据。需要一分钟左右。代码:这里我就不说着种方法了。这题我们可以用,折半枚举。优点:就是能够将时间复杂度降下来,将2^30 变为 2^15 + 2^15解决这题仅仅用了不到1s的时间代码
        阅读全文
            
摘要:二进制枚举参见:https://blog.csdn.net/sugarbliss/article/details/81099340位运算:https://baike.baidu.com/item/%E4%BD%8D%E8%BF%90%E7%AE%97本题:数据太水,假算法也能过。先上一个我都不知到为
        阅读全文
            
                    
                
浙公网安备 33010602011771号