sgu-238 Uncle Vasya and Bags for Potatoes

题目大意:

给你n个背包,然后输入n个数xi,表示第i个背包包含了多少个背包(目标状况)。然后要你求有多少种初始情况可以达到目标状况。

解题思路:

显然对于这种包含关系我们很容易就想到了树上的关系,包含关系就是父亲与儿子的关系,然后在最外面的背包我们把他们都连在一个根节点上。然后一次操作就相当于找一棵子树。然后我们发现如果我们对同一个背包做两次操作相当于没有做,然后我们如果在初始状态上对地上的背包i做了一次操作,然后会发现地上只剩下i,j两个书包了,j是从i中拿出来的,这样我们就只能对j进行操作,然后我们就发现,我们最多不断操作后,最后在操作了某一个书包k后停下来,所以就只有n种情况,然后再加上什么都不做,一共n+1种,然后当n=1的时候特判输出1。

时间: 2024-10-07 17:23:13

sgu-238 Uncle Vasya and Bags for Potatoes的相关文章

SGU 238 Uncle Vasya and Bags for Potatoes 规律+构造

题目链接:点击打开链接 题意: 地上有n个背包,编号从1-n 下面n行第i行: 第一个数字表示背包i里有几个背包. 这样就得到了n个背包的一个状态. 问:有多少个背包状态可以通过一系列的操作达到输入的状态. 每步操作: 选取一个在地面上的背包a,然后把a背包内部的背包放到地上,把地上的放到a背包内部 思路: 我们可以把背包的嵌套关系 用一个图来表示. 就得到了一个森林,然后以地面为根把所有在地上的包相连,就得到了一棵树. 那么对于每次操作相当于换根操作. 所以一共有n-1个方法可以把根移动到其他

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

hdu 1507 Uncle Tom's Inherited Land*(二分)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1853    Accepted Submission(s): 769 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor

HDU 1507 Uncle Tom's Inherited Land*

Uncle Tom's Inherited Land* Special Judge Problem Description Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his great-great-uncle deci

ACM: SGU 101 Domino- 欧拉回路-并查集

sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Description Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The bl

codeforces 584C Marina and Vasya

C. Marina and Vasya Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length

Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

C. Vasya and Basketball Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from does

SGU 116 Index of super-prime 数论+完全背包+输出方案

题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=116 题意好晦涩 给你一个不超过一万的数 问它最少可以用多少个“超级素数”来表示 使“超级素数”之和等于它 如果无法这样表示 输出0 否则 按非降序形式输出方案 数论部分就模板的问题 没什么说的 完全背包方面也很常规 说说[输出方案] 背包九讲的伪码给的是二维dp[]的方法 实际上稍加改动就可以用在一维数组上 用一个rec[]记录dp[]的当前状态是从哪个状态转移而来(即上一个状态) 通过