Sgu 238 Uncle Vasya and bags for potatoes law + Construction

Source: Internet
Author: User

Question link: Click the open link

Question:

There are n backpacks on the ground, numbered from 1-n

Line I in line N below: the first number indicates the number of backpacks in the backpack I.

In this way, a state of N backpacks is obtained.


Q: How many backpacks can be entered through a series of operations.

Each step:

Select a backpack A on the ground, put the backpack inside a on the ground, put the backpack inside a on the ground


Ideas:

We can express the nested relationship of a backpack in a figure.

Then we got a forest and connected all the packets on the ground with the ground as the root. Then we got a tree.

Therefore, each operation is equivalent to a root change operation.

Therefore, a total of N-1 methods can be used to move the root to other places. (Drawing simulation)

(This must be determined when one backpack is used)


#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <map>#include <set>#include <stack>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;int main() {int n, x, y;while (~scanf("%d", &n)) {for (int i = 1; i <= n; ++i) {scanf("%d", &x);while (x -- > 0) {scanf("%d", &y);}}if (n == 1)puts("1");elseprintf("%d\n", n + 1);}return 0;}


Sgu 238 Uncle Vasya and bags for potatoes law + Construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.