1. Title Description: Click to open the link
2. Solving ideas: The problem is solved by looking for a recursive relationship. Set D (i,j,k) to let the height of the pole 1~i line, from the left can see J Root, from the right can see the number of K root scheme. If starting from small to a lot of 1~i-1 root pole row, then the height of the pole I can block a lot of poles, it is difficult to write a recursive style. Here's an angle to consider: Arrange the poles in order from big to small. Assuming that a pole with a height of 2~i has been completed, a pole with a height of 1 will not block any pole wherever it is placed. There are three things in this case:
(1) to the left, you can see it from the left, and you can't see it from the right. (as I≥2), the number of programmes is D (I-1,J-1,K);
(2) If you plug to the far right, you can see it from the right side, from the left to see it, the scheme number is D (i-1,j,k-1);
(3) in the middle (with i-2 insertion position), it is not visible either from the left or from the right, the scheme number is D (i-1,j,k) * (i-2);
This gives the following recursion: D (i,j,k) =d (i-1,j-1,k) +d (i-1,j,k-1) +d (i-1,j,k) * (i-2)
The subject can be pre-hit the table, directly output can.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;typedef long long LL; #define N 20+10int N, L, R; LL d[n][n][n];void init () {d[1][1][1] = 1;for (int i = 2; I <= 20;i++) for (int j = 1; J <= 20;j++) for (int k = 1; K & lt;= 20; k++) D[i][j][k] = D[i-1][j-1][k] + d[i-1][j][k-1] + d[i-1][j][k] * (i-2);} int main () {//freopen ("test.txt", "R", stdin); init (); int t;cin >> t;while (t--) {cin >> n >> l >> R; cout << D[n][l][r] << Endl;} return 0;}
Example 10-15 the arrangement of Poles UVa1638