题目链接:
题意:n维空间中用m个球切。最多能切成多少块?
思路:f[i][j]表示i维空间切j次,f[i][j]=f[i][j-1]+f[i-1][j-1]。试想已经切了j-1次,再切一次,这个球最多能跟其他的j-1个球相交,也就是能切出j-1个切面,增加的块数其实就是n-1维空间中切j-1次得到的块数。比如f[3][3]=f[3][2]+f[2][2],其中f[3][2]=4,f[2][2]=4。想象下,切了两次后再切一次,这一次与之前的两个球的截面是两个圆,那么增加的块数就好比是两个二维的圆能将平面切成多少块。
#include <iostream>
#include <cstdio>#include <string.h>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <set>#include <stack>#include <string>#include <map>#define max(x,y) ((x)>(y)?(x):(y))#define min(x,y) ((x)<(y)?(x):(y))#define abs(x) ((x)>=0?(x):-(x))#define i64 long long#define u32 unsigned int#define u64 unsigned long long#define clr(x,y) memset(x,y,sizeof(x))#define CLR(x) x.clear()#define ph(x) push(x)#define pb(x) push_back(x)#define Len(x) x.length()#define SZ(x) x.size()#define PI acos(-1.0)#define sqr(x) ((x)*(x))#define FOR0(i,x) for(i=0;i<x;i++)#define FOR1(i,x) for(i=1;i<=x;i++)#define FOR(i,a,b) for(i=a;i<=b;i++)#define FORL0(i,a) for(i=a;i>=0;i--)#define FORL1(i,a) for(i=a;i>=1;i--)#define FORL(i,a,b)for(i=a;i>=b;i--)#define rush() int C; for(scanf("%d",&C);C--;)#define Rush(n) while(scanf("%d",&n)!=-1)using namespace std;void RD(int &x){scanf("%d",&x);}void RD(i64 &x){scanf("%lld",&x);}void RD(u32 &x){scanf("%u",&x);}void RD(double &x){scanf("%lf",&x);}void RD(int &x,int &y){scanf("%d%d",&x,&y);}void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}void RD(char &x){x=getchar();}void RD(char *s){scanf("%s",s);}void RD(string &s){cin>>s;}void PR(int x) {printf("%d\n",x);}void PR(i64 x) {printf("%lld\n",x);}void PR(u32 x) {printf("%u\n",x);}void PR(double x) {printf("%.4lf\n",x);}void PR(char x) {printf("%c\n",x);}void PR(char *x) {printf("%s\n",x);}void PR(string x) {cout<<x<<endl;}const int mod=100000007;const i64 inf=((i64)1)<<40;const double dinf=1000000000000000000.0;const int INF=2000000000;const int HASHSIZE=100007;const int N=1000005;i64 f[20][105];int n,m;i64 DFS(int n,int m){ if(m==1) return 2; if(n==1) return 2*m; if(f[n][m]!=-1) return f[n][m]; return f[n][m]=DFS(n,m-1)+DFS(n-1,m-1); }int main(){ RD(m,n); clr(f,-1); PR(DFS(n,m));}