CodeVS4730 特殊等式-1@2@3@...@(N-1)=N

来源:互联网 发布:java面试吹牛 编辑:程序博客网 时间:2024/06/01 08:08

 N<=100


廖...

#include<bits/stdc++.h>using namespace std;#define mod 1000000007int n,tmp1,tmp2;unsigned long long f[110][15000];struct slf{int dep,sum;}tmp;queue<slf> q;int main(){scanf("%d",&n);f[1][5999]=1;q.push((slf){1,5999});while(!q.empty()){tmp1=q.front().dep,tmp2=q.front().sum;q.pop();if(tmp1<n-1) {if(!f[tmp1+1][tmp2+tmp1+1]) q.push((slf){tmp1+1,tmp2+tmp1+1});if(!f[tmp1+1][tmp2-tmp1-1]) q.push((slf){tmp1+1,tmp2-tmp1-1});f[tmp1+1][tmp2+tmp1+1]+=f[tmp1][tmp2];                        f[tmp1+1][tmp2+tmp1+1]%=mod; f[tmp1+1][tmp2-tmp1-1]+=f[tmp1][tmp2];                        f[tmp1+1][tmp2-tmp1-1]%=mod;}}    cout<<f[n-1][6000+n]% mod;}

刘,,

#include<bits/stdc++.h>using namespace std;#define mod 1000000007int n;struct QAQ{int dep;long long sum;}tmp;unsigned long long f[105][15000];const int t=6000;queue<QAQ>q;int main(){scanf("%d",&n);f[1][t-1]=1;q.push(QAQ{1,t-1});while(q.empty()==0){tmp=q.front();q.pop();if(tmp.dep<n-1){if(f[tmp.dep+1][tmp.sum+tmp.dep+1]==0) q.push(QAQ{tmp.dep+1,tmp.sum+tmp.dep+1});                     if(f[tmp.dep+1][tmp.sum-tmp.dep-1]==0) q.push(QAQ{tmp.dep+1,tmp.sum-tmp.dep-1});        f[tmp.dep+1][tmp.sum+tmp.dep+1]+=f[tmp.dep][tmp.sum];                        f[tmp.dep+1][tmp.sum+tmp.dep+1]%=mod;        f[tmp.dep+1][tmp.sum-tmp.dep-1]+=f[tmp.dep][tmp.sum];                        f[tmp.dep+1][tmp.sum-tmp.dep-1]%=mod;}}cout<<f[n-1][t+n] % mod;}


#include <bits/stdc++.h>using namespace std;int f[101][11001];int main(){int n,i,j;cin>>n;f[0][5999]=1;for(i=1;i<=n-2;i++)for(j=950;j<=11001;j++) f[i][j]=(f[i-1][j+i+1]+f[i-1][j-i-1])%1000000007;printf("%d",f[n-2][6000+n]);}


原创粉丝点击