NOIP2008 Universal Group 3 Problem Solving-RLQ

Source: Internet
Author: User

(The first time to write a puzzle, free to spray)

(Just the day before the assignment ha)

(Number of first)

Title Description

When I was in P.E. class, little teacher often took the students with them to play games. This time, the teacher took the students together to do the passing game.
The rules of the game are like this: N students stand in a circle, one of the students holding a ball, when the teacher began to pass the whistle, each classmate can pass the ball to their own about two students of one (left or right), when the teacher in this blow whistle, pass stop, at this time, Holding the ball did not go out of the classmate is the loser, to show you a show.
The clever little guy raises an interesting question: how many different ways of passing can make the ball begin to pass in the small hand, pass the M-time, and return to the little brute hand. The two methods of passing are considered as different methods, and the sequence of the students receiving the ball in the order of catching is different when and only in these two methods. For example, there are three students 1th, 2nd, 3rd, and assume that the small is 1th, the ball passed 3 times back to the small hands of the way there are 1->2->3->1 and 1->3->2->1, a total of 2.

Input/output format

Input format:

The input file ball.in a common line with two integer n,m (3<=n<=30,1<=m<=30) separated by spaces.

Output format:

Output file Ball.out A total of one row, with an integer representing the number of methods that conform to test instructions.

Input/Output sample

Input Sample # #:

3 3

Sample # # of output:

2
Description

40% of the data meet: 3<=n<=30,1<=m<=20
100% of the data meet: 3<=n<=30,1<=m<=30
2008 the third problem of the universal group

--------------------------------------------your friend split line bacteria online------------------------------------------------------------------ --------------------------------

Quite a question of water, if I could have a few years earlier, how good ...

First of all, although the data is small but the direct search will be tle, so DP (no optimal sub-structure is actually no DP)

F[I][J], indicating the number of programs transmitted to the J-man in the first time. By the conditions in question, a person can only take the ball from the left and right side, so obviously the recursive equation f[i][j]=f[i-1][j-1]+f[i-1][j+1], because the station into a ring, so the number 1th and the last special treatment.

Data size does not require scrolling array

Paste Code

1#include <stdio.h>2#include <stdlib.h>3 intpu[301][301]={{0}};4 intMain () {5     intM,n;6scanf"%d%d",&n,&m);7pu[0][1]=1;8      for(intI=1; i<=m;i++){9          for(intj=1; j<=n;j++){Ten             if(j==1) pu[i][j]+=pu[i-1][n]; One             Elsepu[i][j]+=pu[i-1][j-1]; A             if(j==n) pu[i][j]+=pu[i-1][1]; -             Elsepu[i][j]+=pu[i-1][j+1]; -         } the     } -printf"%d", pu[m][1]); -     return 0; -}

Noip2008 Universal Group 3 problems-RLQ

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.