UVA Live 4123 Glenbow Museum math recursion

Source: Internet
Author: User

UVA Live 4123 glenbow Museum Math recursive////topic:////for a polygon parallel to an axis, we can use a sequence to describe, R and O, R =/The vertex angle is 90 degrees, O indicates that the point has an angle of 270. The length of the given sequence. Ask the number of methods that can be composed of these RO sequence//columns of star-shaped polygons (there is a point inside the polygon that can see all the nodes).////thinking://// The number of vertices must be the length of the sequence. N less than 4 does not make a polygon. N is an odd number of times. There are//x, O, and Y. Then * x + * y = 4 * (n-2). Solution x = (n +)/2;//y = (n-4)/2 So n must be an even number, or x, Y is not an integer. OK, so, you can see a glimmer of light//.////method One////F (i,j,k,l) denotes i r,j O, with R (k==0) or O (k==1), R (l==0) or O (l==1) The number of legal schemes at the end//the recurrence equation is//f (i,j,k,0) = f (i-1,j,k,1) + f (i-1,j,k,0);(can be in ... R plus R, can be in .... O add R),//f (i,j,k,1) = f (i-1,j,k,0),////boundary is f (i,0,0,0) = f (0,1,1,1) = 1;//last F (r,o,0,0) + (r,o,1,0) + f (r,o,0,1) is the final answer (R, O for the number of R and O)////method two////F (i,j,k) indicates the number of legitimate schemes with I r,j to R adjacent, R (k==0) or O (k==1), for j>5 case// There is no contribution to the answer. Because we know that there are 4 pairs of adjacent r that can make up a star polygon.//The Recursive equation is://f (i,j,k) = f (i-1,j,k) + f (i-1,j-1,k) (first of all from the beginning of k recursion, this can be sure after we// Can be in the existing ... R There are two options, one +or corresponds to the first, the other +r corresponds to the second)//Boundary condition: f (1,0,0) = f (1,0,1) = 1 The first represents R, the second represents the or.////method three:////combinatorial mathematics. The number of r is x = (n+4)/2; The number of O is y = (n-4)/2. The problem is converted to insert Y in x so that no two//o are adjacent. Binding method, so r on the left side of O://1. The sequence starts with R, which is to select Y O and r in X to form aYes. Altogether c (x, y) = C (x,x-y) = C (x,4)//2. The sequence starts with O and ends with R, so that you select Y-1 O and R in the X-1 to form a team. Altogether C (x-1,y-1) = C (x-1,4)//The final result is the sum of the two. Sentiment:////This question is almost in June when read through the Training Guide basic article, see this question. I was really very food at that time. Even the number of R and O will be pushed for half a day. My geometrical aspect is really too weak. Now look, though I can understand. But it is not possible to write down the state and transfer equations immediately. My ability to deliver is too much food. Moreover, the processing of borders is somewhat blurred. Can be said to be very poor//For example, in method one. I only thought of the state of f (1,0,0,0) = f (0,1,1,1). But ignoring f (i,0,0,0) = 1, which is also some of the transfer//required. The result of oneself tangled up for a long time, still see Daniel's solution only suddenly dawned. And when I saw method three, I suddenly had a bright/ This method is really amazing. This is the magic of combinatorial mathematics. Seriously realize, discover really its wonderful infinity. Although I can not write this problem, but//See you predecessors of the scheme, immediately before the idea of a wide open. Some of the experiences cannot be described in words. Continue to refuel, continue to wander in this magical//problem tour, refueling ~~~fighting! #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> Using namespace Std;typedef long long ll;ll d[1008][1008][2][2];void init () {memset (d,0,sizeof (d));d [1][0][0][0] = 1;d[0 ][1][1][1] = 1;for (int i=1;i<=1000;i++) d[i][0][0][0] = 1;for (int k=0;k<2;k++) {for (Int. i=1;i<=1000;i++) for ( int j=1;j<=1000;j++) {d[i][j][k][0] = D[i-1][j][k][0] + d[i-1][j][k][1];d [i][j][k][1] = d[i][j-1][k][0];}}} int main () {init (); int N;freopen ("1.txt", "R", stdin); Ios::synC_with_stdio (false), int kase = 1;while (cin>>n) {if (!n) break;cout << "case" << kase++ << ":"; if ( n<4 | | (n&1)) {cout << 0 << endl;continue;} int a = (n+4)/2;int B = (n-4)/2;ll ans = d[a][b][0][0] + d[a][b][0][1]+d[a][b][1][0];cout<< ans << endl;} return 0;} #include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;typedef Long Long ll;ll d[1008][8][2];void init () {memset (d,0,sizeof (d));d [1][0][0] = 1;d[1][0][1] = 1;for (int k=0;k& lt;2;k++) for (int i=2;i<=1000;i++) for (int j=0;j<5;j++) {D[i][j][k] = d[i-1][j][k];if (j>0) d[i][j][k] + = d[i-1] [J-1] [K];}} int main () {init (); Ios::sync_with_stdio (false); int N;int Kase = 1;while (cin>>n) {if (!n) break;cout << "Case" << kase++ << ":"; if (N < 4 | | (n&1)) {cout << 0 << endl;continue;} int a = (n+4) >>1;ll res = d[a][4][0] + d[a][4][1] + d[a][3][1];cout << res << Endl;}} #incLude <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std; typedef long Long Ll;int main () {ll n;ios::sync_with_stdio (false); int kase = 1;while (cin>>n) {if (!n) Break;cout < < "case" << kase++ << ":"; if (N<4 | | (N & 1)) {cout << 0 << endl;continue;} ll r = (n+4)/2;ll ans1 = R * (r-1) * (r-2) * (r-3)/24;r--;ll ans2 = R * (r-1) * (r-2) * (r-3)/24;cout << ans1 + Ans2 << Endl;} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA Live 4123 Glenbow Museum math recursion

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.