1197: [HNOI2006] Flower Fairy Magic Time limit: ten Sec Memory Limit: 162 MB
Submit: 771 Solved: 448
[Submit] [Status] Description
Input
Contains two integers, separated by a space, the first integer represents the number of times the magic is applied M, and the second integer represents the dimension n of the space. Among them, 1≤m≤100,1≤n≤15.
Output
Contains only an integer that indicates how many different flowers the flower fairy can get after it implements M magic in n-dimensional space.
Sample Input3 1Sample Output6
Dp.
Test instructions is equivalent to placing m n-dimensional balls, up to a few parts of the n-dimensional space.
F[I][J] means that a J i-dimensional ball placed in an i-dimensional space divides the space into several parts.
F[I][J]=F[I][J-1]+F[I-1][J-1]
Consider putting in the first J Ball, has been divided into f[i][j-1] space;
Because I sphere the part that intersects with the I-dimensional ball becomes i-1 dimension (line intersection is point, the intersection is line ...) ), the first J ball intersects with j-1 balls, so it is f[i-1][j-1].
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include < Cstdlib> #define LL Long longusing namespace Std;int n,m; LL F[105][105];int Main () { scanf ("%d%d", &m,&n), for (int i=1;i<=m;i++) f[1][i]=i*2;f[2][1]=2;for (int i =2;i<=n;i++) for (int j=2;j<=m;j++) {if (j==1) F[i][j]=4;else f[i][j]=f[i][j-1]+f[i-1][j-1];} Cout<<f[n][m]<<endl;return 0;}
Sentiment:
1.WA is due to initialization of write error
2. Initialize F[1][i] Why is it equal to 2*i? Because in a straight line, two endpoints are added each time, the maximum number of lines can be divided into two parts ("part" and test instructions consistent)
"Bzoj 1197" [HNOI2006] the magic of the flower Fairy