|
推荐
楼主 |
发表于 2018-7-6 18:30:49
|
只看该作者
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- long long n,k,whi[100],bla[100],lw,lb,all=0,f[100][100];
- void init()
- {
- memset(bla,0,sizeof(bla));
- memset(whi,0,sizeof(whi));
- for(int i=1;i<=n;i++)
- if(i<=n/2)
- {
- whi[i]=2*i-1;
- bla[i]=2*i;
- }
- else
- {
- if(whi[n+1-i]==0)
- whi[i]=whi[i-1]+2;
- else
- whi[i]=whi[n+1-i];
- bla[i]=bla[n-i];
- }
- }
- long long suan_bla(int qi)
- {
- memset(f,0,sizeof(f));
- if(qi==0)
- return 1;
- f[1][1]=bla[1];
- for(int i=2;i<=qi;i++)
- f[1][i]=0;
- for(int i=2;i<=lb;i++)
- {
- f[i][1]=f[i-1][1]+bla[i];
- for(int j=2;j<=qi;j++)
- f[i][j]=f[i-1][j]+max((long long)0,f[i-1][j-1]*(bla[i]-j+1));
- }
- return f[lb][qi];
- }
- long long suan_whi(int qi)
- {
- memset(f,0,sizeof(f));
- if(qi==0)
- return 1;
- f[1][1]=whi[1];
- for(int i=2;i<=qi;i++)
- f[1][i]=0;
- for(int i=2;i<=lw;i++)
- {
- f[i][1]=f[i-1][1]+whi[i];
- for(int j=2;j<=qi;j++)
- f[i][j]=f[i-1][j]+max((long long)0,f[i-1][j-1]*(whi[i]-j+1));
- }
- return f[lw][qi];
- }
- int main()
- {
- scanf("%lld%lld",&n,&k);
- while(n!=0||k!=0)
- {
- if(n==1)
- {
- if(k==1||k==0)
- printf("1\n");
- else
- printf("0\n");
- scanf("%lld%lld",&n,&k);
- continue;
- }
- all=0;
- init();
- lw=n,lb=n-1;
- sort(whi+1,whi+lw+1);
- sort(bla+1,bla+1+lb);
- for(int i=0;i<=k;i++)
- all+=suan_bla(i)*suan_whi(k-i);
- printf("%lld\n",all);
- scanf("%lld%lld",&n,&k);
- }
- return 0;
- }
复制代码 |
|