Codeforces Round #263
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的更多相关文章
- 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...
- Codeforces Round #263 (Div. 1)
B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...
- codeforces Round #263(div2) D. Appleman and Tree 树形dp
题意: 给出一棵树,每个节点都被标记了黑或白色,要求把这棵树的其中k条变切换,划分成k+1棵子树,每颗子树必须有1个黑色节点,求有多少种划分方法. 题解: 树形dp dp[x][0]表示是以x为根的树 ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- 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 ...
- Codeforces Round #263 (Div. 2) A B C
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...
- 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 ...
- Codeforces Round #263 (Div. 2) proC
题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- [原创]使用GCC创建 Windows NT 下的内核DLL
原文链接:使用GCC创建 Windows NT 下的内核DLL 在温习<<Windows 2000 Driving>>分层驱动程序一章的时候,看到了关于紧耦合驱动连接方式,这种 ...
- (转)设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)
转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义.靠,这货其实就是间隔,起个名字这么让 ...
- vmware 使用技巧
1.虚拟机如何进入BIOS界面? 方法: 1) 开机按F2 2) 若来不及按F2的话,可以通过以下 2. 如何让虚拟机进入安全模式? 方法:开机快速按F8 3. 当不能连接到vCenter Serve ...
- 偷懒的inline-block解决方法
最近这几天看了inline-block的用法,用它来代替浮动实现水平排列很不错,只是要解决一下浏览器兼容和间隙的问题.关于ie6,7的兼容问题 <inline-block 前世今生>(ht ...
- 無塵室(Clean Room)的級數標準規格
無塵室又稱潔淨室,是將一定空間範圍內空氣的微塵粒子.有害氣體.細菌等之污染物控制在一定的數量內.無塵室的等級是以一立方英呎含有多少大於0.5um的微塵粒子來定義的.下表是根據「美國聯邦標準209D規格 ...
- 介绍几种IC卡
介绍几种IC卡 Mifare卡:工作频率:13.56MHZ数据保存期:10年 操作时间:96ms读写距离:2.5-10cm 存储容量:8Kbit尺寸:85.6x54x0.76mm 存储器类型:EE ...
- rsyslog ~ 波浪号
<pre name="code" class="html">Using negation can be useful if you would li ...
- 柯南君:看大数据时代下的IT架构(9)消息队列之RabbitMQ--案例(RPC起航)
二.Remote procedure call (RPC)(using the Java client) 三.Client interface(客户端接口) 为了展示一个RPC服务是如何使用的,我们将 ...
- linux内核源码阅读之facebook硬盘加速flashcache之五
正常流程到flashcache_map的1623行或1625行,按顺序先看读流程: 1221static void 1222flashcache_read(struct cache_c *dmc, s ...
- ocx控件获取使用App的窗口句柄
在CXxxCtrl文件中 HWND hAppWnd = NULL; if (m_pInPlaceSite != NULL) m_pInPlaceSite->GetWindow(&hApp ...