吐槽:一辈子要在DIV 2混了。

A,B,C都是简单题,看AC人数就知道了。

A:如果我们定义数组为N*N的话就不用考虑边界了

 #include<iostream>
#include <string>
#include <vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f
#define N 12345
typedef long long ll;
int a[N];
char s[][];
int main()
{
int n;
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%s",s[i]+); int flag=;
for (int i=;i<=n;i++)
for (int j=;j<=n;j++){
int ans=;
if (s[i-][j]=='o') ans++;
if (s[i][j-]=='o') ans++;
if (s[i][j+]=='o') ans++;
if (s[i+][j]=='o') ans++;
if (ans&) {flag=;break;}
} if (flag) printf("YES");
else printf("NO");
return ;
}

B:语文实在...。。

可以是贪心。。。

只要对26个字母排序

233

 #include<iostream>
#include <string>
#include <vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f
#define N 123456
typedef long long ll;
ll a[N];
string s;
int main()
{
int n;
ll k;
cin>>n>>k;
cin>>s;
for (int i=;i<s.size();i++)
a[s[i]-'A']++;
sort(a,a+);
ll ans=;
for (int i=;i>=;i--)
{
if (k>=a[i]) {ans+=a[i]*a[i];k-=a[i];
}
else {ans+=k*k;break;}
}
cout<<ans<<endl;
return ;
}

这题也是贪心做法。。

因为我们要加的数的个数是一定的。。。

如果排序好,尽量加大的,就OK了。。所以每次我们把最小的踢出去。

就可以算出每个数要加多少。

 #include<iostream>
#include <string>
#include <vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f
#define N 323456
typedef long long ll;
ll a[N];
string s;
int main()
{
int n;
cin>>n;
for (int i=;i<=n;i++)cin>>a[i];
ll ans=;
sort(a+,a+n+);
for (int i=;i<n;i++)
ans+=a[i]*(i+);
ans+=a[n]*n;
cout<<ans;
return ;
}

D:练了不少树形DP了,但是这题完全没思路。真是渣一辈子DIV 2。

思路:定义DP[I][1]表示以I为根的数中有BLACK节点

DP[I][0]表示没有BLACK节点。。

转移方程

U是ROOT的子节点

初始:DP[ROOT][COLOR[ROOT]]=1;

DP[ROOT][1]=DP[ROOT][1]*DP[U][1]+DP[ROOT][0]*DP[U][1]+DP[ROOT][1]*DP[U][0];

DP[ROOT][0]=DP[ROOT][0]*DP[U][0]+DP[ROOT][0]*DP[U][1];

 #include<iostream>
#include <string>
#include <vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 112345
#define inf 1000000007
typedef long long ll;
using namespace std;
vector<int>G[N];
ll dp[N][];
int col[N];
int n; void dfs(int root,int pre)
{
dp[root][col[root]]=;
for (int i=;i<G[root].size();i++)
{
int x=G[root][i];
if (x==pre) continue;
dfs(x,root);
dp[root][]=(dp[root][]*dp[x][]%inf+dp[root][]*dp[x][]+dp[root][]*dp[x][])%inf;
dp[root][]=(dp[root][]*dp[x][]%inf+dp[root][]*dp[x][]%inf)%inf;
}
} int main()
{
scanf("%d",&n);
for (int i=;i<n;i++)
{
int x;
scanf("%d",&x);
G[i].push_back(x);
G[x].push_back(i);
}
for (int i=;i<n;i++)
scanf("%d",&col[i]);
dfs(,-);
printf("%d\n",dp[][]);
return ;
}

后记:

树形DP比较抽象。。。多做题才能提高

Codeforces Round #263 (Div. 2)的更多相关文章

  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 (Div. 2) D. Appleman and Tree(树形DP)

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

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

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

  6. 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 ...

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

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

  8. Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)

    数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...

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

    题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. Google -We’re Sorry....

    Author:KillerLegend From:http://www.cnblogs.com/killerlegend/p/3734840.html Date:2014.5.18 一大清早 一大早起 ...

  2. smarty第一天

    1.安装 安装Smarty发行版在/libs/目录里的库文件(就是解压了). 2.工作原理 美工人员 1. 写模板, HTML CSS JavaScript 2. 使用Smarty表现逻辑 放变量, ...

  3. Python核心编程--学习笔记--2--Python起步(下)

    16 文件和内建函数open(),file() 打开文件: fobj = open(filename, 'r') for eachLine in fobj: print eachLine, #由于每行 ...

  4. psql: 致命错误: 用户 "postgres" Ident 认证失败

    RedHat: 问题: psql -U postgres 时出现:psql: 致命错误:  用户 "postgres" Ident 认证失败 解决: 修改 /var/lib/pgs ...

  5. 《高性能javascript》读书笔记:P1减少跨作用域的变量访问

    前端优化,有两个意义:1.为了让用户在浏览网页时获得更好的体验 2.降低服务器端的访问压力,节省网络流量. 除了换个好主机连上个千兆网这样的硬件问题,优化部分的实现方式目前也大致两种,一种是页面级别的 ...

  6. android开发系列之MVP设计模式

    最近在开发一个android的项目中,发现了一个很实用的设计模式(MVP).大家可能一看到这个名字就有点蒙,MVP到底是什么鬼呢?它的好用到底体现在哪呢?别着急,下面就让我们一一分享出来. 说到MVP ...

  7. 依网友要求发个修改award bios的方法(刷CPU微码)

    注意本文修改的是award BIOS 首先看自己的CPUID是哪个代码,打开CPU-Z如下图红圈中就是,此CPUID就是067A,好了下面就可以开始准备工作 准备好BIOS文件,以及CPU微码文件.可 ...

  8. centos下各种c++库文件的安装

    Centos编译boost   1.下载最新的boost http://www.boost.org/   2.解压文件 tar -xzvf boost_1_45_0.tar.gz    3.编译bja ...

  9. iOS中MVC设计模式

    在组织大型项目的代码文件时,我们常用MVC的思想.MVC的概念讲起来非常简单,就和对象(object)一样.但是理解和应用起来却非常困难.今天我们就简单总结一下MVC设计理念. MVC(Model V ...

  10. [转]UDP/TCP穿越NAT的P2P通信方法研究(UDP/TCP打洞 Hole Punching)

     [转]UDP/TCP穿越NAT的P2P通信方法研究(UDP/TCP打洞 Hole Punching) http://www.360doc.com/content/12/0428/17/6187784 ...