http://codeforces.com/contest/461

A.水题



B.太挫了,竟然被hack了一发。。。。



C.贪心。。竟然没看出来时哈夫曼编码问题



D.题目大意:给一棵树,每一个点为白色或黑色,切断一些边,使得每一个连通块有且仅有一个黑点,问划分方案数。



树形DP,

设状态:

dp[v][0]表示以v为根的子树中没有黑点,dp[v][1]有一个黑点。

状态方程:

dp[v][1] = dp[v][1]*dp[son][0] + dp[v][0]*dp[son][1] + dp[v][1]*dp[son][1]

dp[v][0] = dp[v][0]*dp[son][0] + dp[v][0]*dp[son][1]

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn = 100000 + 100;
vector<int> g[maxn];
int clr[maxn];
LL dp[maxn][2];
int n; void dfs(int u, int p)
{
dp[u][clr[u]] = 1;
for(int i=0; i<g[u].size(); ++i)
{
int &v = g[u][i];
if(v==p) continue;
dfs(v, u);
dp[u][1] = (dp[u][1]*dp[v][0]%mod + dp[u][0]*dp[v][1]%mod + dp[u][1]*dp[v][1]%mod) % mod;
dp[u][0] = (dp[u][0]*dp[v][1]%mod + dp[u][0]*dp[v][0]%mod) % mod;
}
}
int main()
{
scanf("%d", &n);
int x;
for(int i=1; i<n; ++i)
{
scanf("%d",&x);
g[i].push_back(x);
g[x].push_back(i);
}
for(int i=0; i<n; ++i)
{
scanf("%d", &clr[i]);
} dfs(0, -1);
printf("%I64d\n", dp[0][1]);
return 0;
}

E.





Div1 D Appleman and Complicated Task





Div1 E Appleman and a Game

Codeforces Round #263的更多相关文章

  1. 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman

    题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...

  2. Codeforces Round #263 (Div. 1)

    B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...

  3. Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】

    题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...

  4. codeforces Round #263(div2) D. Appleman and Tree 树形dp

    题意: 给出一棵树,每个节点都被标记了黑或白色,要求把这棵树的其中k条变切换,划分成k+1棵子树,每颗子树必须有1个黑色节点,求有多少种划分方法. 题解: 树形dp dp[x][0]表示是以x为根的树 ...

  5. Codeforces Round #263 (Div. 2)

    吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...

  6. Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)

    题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...

  7. Codeforces Round #263 (Div. 2) A B C

    题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...

  8. Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新

    C. Appleman and a Sheet of Paper   Appleman has a very big sheet of paper. This sheet has a form of ...

  9. Codeforces Round #263 (Div. 2) proC

    题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. 通过SocketLog快速分析php程序

    转载自http://www.thinkphp.cn/topic/10846.html 正在运行的API有bug,不能var_dump进行调试,因为会影响client的调用.这时候用SocketLog最 ...

  2. codeforces 8C. Looking for Order 状压dp

    题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include < ...

  3. 第6章 堆排序,d叉堆,优先队列

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define leftChild(i) (2*(i ...

  4. 异步流程控制库GoWithTheFlow

    异步流程控制库GoWithTheFlow 一个尾触发方式来控制异步流程的库, 有seq(顺序执行) par(同步执行) 两种方法 博客 http://notes.jetienne.com/2011/0 ...

  5. Activity篇章参考

    附上学习这部分知识的时候收集的一些比较好的链接: Task and backStack|Android Developer adb shell dumpsys activity 单个apk多进程 Ac ...

  6. BZOJ 1143 [CTSC2008]祭祀river(二分图匹配)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1143 [题目大意] 给出一张有向图,问最大不连通点集,连通具有传递性 [题解] 我们将 ...

  7. iOS6和iOS7代码的适配(3)——坐标适配

    由于iOS7里面status bar和视图是重叠在一起了,所以应用的y坐标就没法和以前一致了,需要重新计算设定.基本上,你的应用用Xcode5运行一下就能看见这个问题,这里写了一个最简单的例子,一个V ...

  8. 米兰站热卖:奢侈品电商困局已破?-搜狐IT

    米兰站热卖:奢侈品电商困局已破?-搜狐IT 米兰站热卖:奢侈品电商困局已破?

  9. Ubuntu14.04 Server Apache2+subversion环境搭建

    自从工作后,发现之前的代码开发太随便啦,于是经过不到两年的工作积累,打算在自己开发软件的过程中好好管理自己的项目.于是打算搭建自己的项目服务器,去年搭建过一次,但是由于没有记录,现在需要再来一遍,好多 ...

  10. Zookeeper 编程

    ZooKeeper编程(一) 杂记 ZooKeeper的用途:distributed coordination;maintaining configuration information, namin ...