Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<cstring>
- #include<math.h>
- #include<algorithm>
- #include<iostream>
- #include<string>
- #include<vector>
- #include<stdlib.h>
- #include<set>
- #include<map>
- #include<utility>
- #include<time.h>
- #include<queue>
- #include<limits.h>
- using namespace std;
- typedef vector<int>::iterator vit;
- typedef string::iterator sit;
- typedef vector<int>::reverse_iterator rvit;
- typedef long long ll;
- typedef long double ld;
- const int N=1100;
- const ll MOD=1000000000+7;
- ll mod(ll x)
- {
- x%=MOD;
- if(x<0)
- x+=MOD;
- return x;
- }
- struct TPos
- {
- ll total,num;
- TPos()
- {
- total=num=0;
- }
- void update_total(ll x)
- {
- total+=x;
- total=mod(total);
- }
- void update_num(ll x)
- {
- num+=x;
- num=mod(num);
- }
- };
- TPos d[N][N];
- int n;
- ll c,ans=0;
- void push(int pos, int len)
- {
- int lim=len;
- if(pos+lim>n)
- lim=n-pos;
- ll total_score=d[pos][len].total,num_score=d[pos][len].num;
- if(pos==0)
- {
- total_score*=c;
- num_score*=c;
- }
- else
- {
- total_score*=(c-1);
- num_score*=(c-1);
- }
- for(int i=1;i<=lim;++i)
- {
- d[pos+i][len].update_total(total_score);
- d[pos+i][len].update_num(num_score);
- if(i==len)
- {
- ll z=pos==0?c:c-1;
- d[pos+i][len].update_num((d[pos][i].total-d[pos][i].num)*z);
- }
- }
- }
- void gen()
- {
- for(int j=1;j<=n;++j)
- {
- d[0][j].total=1;
- for(int i=0;i<n;++i)
- {
- push(i,j);
- }
- }
- ans=0;
- for(int j=1;j<=n;++j)
- {
- ans+=j*d[n][j].num;
- ans=mod(ans);
- }
- }
- const bool D=0;
- int main()
- {
- if(D)
- {
- freopen("test.in","r",stdin);
- freopen("test.out","w",stdout);
- }
- else
- {
- freopen("sequence.in","r",stdin);
- freopen("sequence.out","w",stdout);
- }
- scanf("%d%I64d",&n,&c);
- gen();
- printf("%I64d\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment