ZOJ1427 POJ1694 An Old Stone Game
来源:互联网 发布:语言障碍评估软件 编辑:程序博客网 时间:2024/05/17 23:46
很简单的递归题。注意记录下节点子节点需要的石子数,然后从最大开始排列,取第一个为需要的石头数,遍历记录,如果余下的石头不足以支付,则需要补充。
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-03-21 19:27 # Filename: ZOJ1427 POJ1694 An Old Stone Game.cpp # Description : ******************************************************************************/#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#define MAX 210using namespace std;int children[MAX][MAX];int func(const int &r){int array[MAX];if(children[r][0]==0)return 1;int cnt=0;while(children[r][cnt]){array[cnt]=func(children[r][cnt]);++cnt;}sort(array,array+cnt,greater<int>());int ans=array[0],tmp=array[0]-1;for(int i=1;i<cnt;++i)if(tmp<array[i]){ans+=(array[i]-tmp);tmp=array[i]-1;}else--tmp;return ans;}int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int n,ncases,parent,tmp;scanf("%d",&ncases);while(ncases--){scanf("%d",&n);memset(children,0,sizeof(children));for(int i=0;i<n;++i){scanf("%d%d",&parent,&tmp);for(int j=0;j<tmp;++j)scanf("%d",&children[parent][j]);}int ans=func(1);printf("%d\n",ans);} return 0;}
- ZOJ1427 POJ1694 An Old Stone Game
- POJ1694 An Old Stone Game
- POJ1694 An Old Stone Game (树,排序) .
- POJ1694,An Old Stone Game,读懂题目+dfs
- An Old Stone Game(poj1694模拟与排序)
- 1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ--1694--An Old Stone Game
- An old Stone Game ~~GarsiaWachs算法
- poj 1694 An old stone game
- 北大oj 1694 An Old Stone Game
- POJ 1694 An Old Stone Game 笔记
- POJ 1738 An old Stone Game 笔记
- POJ 1694 An Old Stone Game【递归+排序】
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj 1694 An Old Stone Game 树形dp
- 按回车,直接登陆
- OpenCV學習心得(6) -- 圖像的縮放
- 一个Linux下C线程池的实现
- slice的c++映射
- Java程序员应该了解的10个面向对象设计原则
- ZOJ1427 POJ1694 An Old Stone Game
- 第五周实验报告(1-3)
- ICE的AMI方法调用
- 使用JavaScript完成最简单加密解密和模仿QQ的窗口抖动效果
- oracle net configuration assistant安装失败
- 第五周实验报告2
- effective C++笔记之条款33: 明智地使用内联
- jquery内容选择器
- ubuntu下安装SDL