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

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

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

  1. #include<iostream>
  2. #include <string>
  3. #include <vector>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<string>
  8. #include<algorithm>
  9. using namespace std;
  10. #define inf 0x3f3f3f
  11. #define N 12345
  12. typedef long long ll;
  13. int a[N];
  14. char s[][];
  15. int main()
  16. {
  17. int n;
  18. scanf("%d",&n);
  19. for (int i=;i<=n;i++)
  20. scanf("%s",s[i]+);
  21.  
  22. int flag=;
  23. for (int i=;i<=n;i++)
  24. for (int j=;j<=n;j++){
  25. int ans=;
  26. if (s[i-][j]=='o') ans++;
  27. if (s[i][j-]=='o') ans++;
  28. if (s[i][j+]=='o') ans++;
  29. if (s[i+][j]=='o') ans++;
  30. if (ans&) {flag=;break;}
  31. }
  32.  
  33. if (flag) printf("YES");
  34. else printf("NO");
  35. return ;
  36. }

B:语文实在...。。

可以是贪心。。。

只要对26个字母排序

233

  1. #include<iostream>
  2. #include <string>
  3. #include <vector>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<string>
  8. #include<algorithm>
  9. using namespace std;
  10. #define inf 0x3f3f3f
  11. #define N 123456
  12. typedef long long ll;
  13. ll a[N];
  14. string s;
  15. int main()
  16. {
  17. int n;
  18. ll k;
  19. cin>>n>>k;
  20. cin>>s;
  21. for (int i=;i<s.size();i++)
  22. a[s[i]-'A']++;
  23. sort(a,a+);
  24. ll ans=;
  25. for (int i=;i>=;i--)
  26. {
  27. if (k>=a[i]) {ans+=a[i]*a[i];k-=a[i];
  28. }
  29. else {ans+=k*k;break;}
  30. }
  31. cout<<ans<<endl;
  32. return ;
  33. }

这题也是贪心做法。。

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

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

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

  1. #include<iostream>
  2. #include <string>
  3. #include <vector>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<string>
  8. #include<algorithm>
  9. using namespace std;
  10. #define inf 0x3f3f3f
  11. #define N 323456
  12. typedef long long ll;
  13. ll a[N];
  14. string s;
  15. int main()
  16. {
  17. int n;
  18. cin>>n;
  19. for (int i=;i<=n;i++)cin>>a[i];
  20. ll ans=;
  21. sort(a+,a+n+);
  22. for (int i=;i<n;i++)
  23. ans+=a[i]*(i+);
  24. ans+=a[n]*n;
  25. cout<<ans;
  26. return ;
  27. }

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];

  1. #include<iostream>
  2. #include <string>
  3. #include <vector>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<algorithm>
  8. #define N 112345
  9. #define inf 1000000007
  10. typedef long long ll;
  11. using namespace std;
  12. vector<int>G[N];
  13. ll dp[N][];
  14. int col[N];
  15. int n;
  16.  
  17. void dfs(int root,int pre)
  18. {
  19. dp[root][col[root]]=;
  20. for (int i=;i<G[root].size();i++)
  21. {
  22. int x=G[root][i];
  23. if (x==pre) continue;
  24. dfs(x,root);
  25. dp[root][]=(dp[root][]*dp[x][]%inf+dp[root][]*dp[x][]+dp[root][]*dp[x][])%inf;
  26. dp[root][]=(dp[root][]*dp[x][]%inf+dp[root][]*dp[x][]%inf)%inf;
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. scanf("%d",&n);
  33. for (int i=;i<n;i++)
  34. {
  35. int x;
  36. scanf("%d",&x);
  37. G[i].push_back(x);
  38. G[x].push_back(i);
  39. }
  40. for (int i=;i<n;i++)
  41. scanf("%d",&col[i]);
  42. dfs(,-);
  43. printf("%d\n",dp[][]);
  44. return ;
  45. }

后记:

树形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. 【easyui】--普通js中获取easyui中分页信息(page,pageSize等)

    对于datagrid,获取其分页信息: 方法: var pageopt = $('#list_data').datagrid('getPager').data("pagination&quo ...

  2. cxgrid对经过筛选过的数据的选择(反选)

    // 下面这个主要是对查询出来的数据, 经过筛选后得到的数据中进行反选操作 ,然后对选择的数据进行修改(全选或选择一部分也可以根据些代码修改) Screen.Cursor := crHourGlass ...

  3. 10.python中的序列

    本来说完字符串.数字.布尔值之后,应该要继续讲元祖.列表之类的.但是元祖和列表都属于序列,所以有必要先讲讲python的序列是什么. 首先,序列是是Python中最基本的数据结构.序列中的每个元素都分 ...

  4. C开发 中原子性操作 , 除了快什么都不剩下了

    题外话 今天,听歌曲听到一首缅怀迈克尔·杰克逊的歌曲 如下: http://music.163.com/#/song?id=1696048  Breaking News 每次听迈克尔 音乐,特别有战斗 ...

  5. 快速同步mysql数据到redis中

    MYSQL快速同步数据到Redis 举例场景:存储游戏玩家的任务数据,游戏服务器启动时将mysql中玩家的数据同步到redis中. 从MySQL中将数据导入到Redis的Hash结构中.当然,最直接的 ...

  6. Outlook打不开? 进程一大堆!

    问题描述: ====== 关闭Outlook应用程序后,Outlook.exe进程仍在任务管理器里继续运行,不能关闭. 原因: ====== Outlook的插件或者扩展程序阻止Outlook关闭 解 ...

  7. Java生成唯一的ID

    public class UIDGenerator { private static Date date = new Date(); private static StringBuilder buf ...

  8. yum代理设置

    vi /etc/yum.conf 加入以下:proxy=http://代理服务器ip:port 如果代理需要账号密码:proxy_username=userproxy_password=密码

  9. Linq To SQLite by CRUD

    1, 希望使用linqtoSQLite 来对数据库实现CRUD, 开发环境 VS2013, 1.1 在网上找到了 LINQ to DB T4 Models, 配置参考网址链接: http://www. ...

  10. 35.在PCB中删除元件

    在PCB Editor里面,如果想进行什么操作,首先得点击这个命令,再点击你要操作的区域/元件,最后右键选择"Done",这样你才能完成一个操作.