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. Ajax中send方法的使用

    Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...

  2. WEB开发之如何改善PHP开发方式

    改善PHP开发方式一般可以分为以下几种实现方式: 1.组织和样式     找出一种适合你的组织方法和编码样式,并且一直坚持下去,这样的话,你的代码的组织和布局会变得十分有条理.我们不应该轻视代码的组织 ...

  3. 用C语言制作小型商品信息管理系统过程中的问题

    大神请默默飘过... 以下是第一次制作时的源码: // 商品信息管理.cpp : 定义控制台应用程序的入口点. // // 小型商品信息管理系统.cpp : 定义控制台应用程序的入口点. // #in ...

  4. Oracle EBS-SQL (SYS-1): sysadmin_用户职责查询.sql

    select fu.user_name 用户名, fu.description 用户说明, frv.RESPONSIBILITY_NAME 职责名称, REQUEST_GROUP_NAME 报表组, ...

  5. [LeetCode][Python]15:3Sum

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 15: 3Sumhttps://oj.leetcode.com/problem ...

  6. [基础]RHEL6下iSCSI客户端挂载配置

    本文根据鸟哥私房菜进行操作:http://linux.vbird.org/linux_enterprise/xen.php?thisscreen=800x600 一.侦测 [root@vhost3 ~ ...

  7. 借@阿里巴巴 耍了个帅——HTML5 JavaScript实现图片文字识别与提取

    写在前面 8月底的时候,@阿里巴巴 推出了一款名为“拯救斯诺克”的闯关游戏,作为前端校园招聘的热身,做的相当不错,让我非常喜欢.后来又传出了一条消息,阿里推出了A-star(阿里星)计划,入职阿里的技 ...

  8. The "Run One Program Only" Phenomenon

    As previously discussed,embedded devices normally embody the functionality they implement.In other w ...

  9. php 设置字符集为utf-8

    header("Content-Type:text/html;charset=utf-8");

  10. SharePoint 2013 Designer 自己定义操作菜单

    众所周知,我们在SharePoint的二次开发中,常常会加入ECB菜单或者Ribbon菜单,通常我们会採取Feature的方式去加入一个Xml,或者採取JavaScript的方式.当然.除此之外,还能 ...