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 and Output sample input Example # #:
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
---------------------------------------I'm a gorgeous split-line----------------------------------------------------------------
Water problem, just see easily think of no brain search, each one on the enumeration of its right position and left position.
But write the code to allow (a) easy (fixed) time-out (only over five points), the mob code is as follows:
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <queue>
5 #include <cmath>
6 #include <algorithm>
7 #include <cstdlib>
8 using namespace std ;
9 int n,m,ans=0;
Ten int read () {
one int X=0,f=1;char ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} x*f return;
(int,int);
Std::ios::sync_with_stdio int main (),
{ (false); cin>>n>>m; search (1,0); cout<<ans; return 0;
(int d,int c)--(int.) a=d-1;b=d+1; if (d==1) a=n;if (d==n) b=1; if (c==m&&d==1) ans++; if (c<m), c+=1; search (a,c); search (b,c); c-=1;
PNS }
38}
Because time-out, go back to see the topic, found that each state can be used in the previous launch,
and is not valid, so consider the rules, the code is as follows:
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <queue>
5 #include <cmath>
6 #include <algorithm>
7 #include <cstdlib>
8 using namespace std ;
9 int dp[33][33];
Ten int read () {
one int X=0,f=1;char ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} x*f return;
(
) + int main (),
{ Std::ios::sync_with_stdio (false); n,m int; cin>>n>>m;
for (int i=1;i<=n;i++) dp[i][min (i-1,31-i)]=1;
j=1;j<=m;j++ for (int i=1;i<=n;i++) (int) (int.) ( i==1) dp[1] [J]=dp[n][j-1]+dp[2][j-1]; if (i==n) dp[i][j]=dp[1][j-1]+dp[i-1][j-1]; if (i>1&&i<n) dp[i][j]=dp[i-1][j-1]+dp[i+1][j-1]; cout<<dp[1][m]<<endl;
} return 0;
32}
So, do not see the scope of the problem of small data immediately without a brain search,
It is still necessary to consider an efficient algorithm before you can guarantee the score.