
容斥原理
取竹
Hai capito?
展开
-
[bzoj]1042: [HAOI2008]硬币购物
神奇的题目,dp+容斥。一开始基本没思路,看了别人的题解后才理解。 令f数组为硬币无数量限制时达到s的种类,先预处理完。 然后对于每次询问只要加出一个sum后减去重复部分。(容斥) #include #define ll long long using namespace std; const int N=100005; int c[6],tot; int d[6],s; ll a原创 2017-04-18 20:58:01 · 226 阅读 · 0 评论 -
[bzoj]4596: [Shoi2016]黑暗前的幻想乡
此题用容斥做,答案就是没有不选的-一个不选的+两个不选的-三个不选的…… 2^n枚举出不选的,算方案使用矩阵树定理。 #include #include #include #include #define ll long long using namespace std; const ll pp=1000000007; struct node{ int u[400],v[40原创 2017-06-14 09:05:28 · 390 阅读 · 0 评论