上午
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 freopen("str.in","r",stdin); 6 freopen("str.out","w",stdout); 7 string s="a"; 8 int n,k; 9 cin>>n>>k; 10 if(k>n) 11 { 12 cout<<-1; 13 return 0; 14 } 15 if(n==1 && k==1) 16 { 17 cout<<'a'; 18 return 0; 19 } 20 if(k==1 && n>1) 21 { 22 cout<<-1; 23 return 0; 24 } 25 if(k==2) 26 { 27 for(int i=1;i<n;i++) 28 { 29 if(s[i-1]=='a') 30 s+='b'; 31 else 32 s+='a'; 33 } 34 cout<<s; 35 return 0; 36 } 37 if(k>2) 38 { 39 for(int i=1;i<n-k+2;i++) 40 { 41 if(s[i-1]=='a') 42 s+='b'; 43 else 44 s+='a'; 45 } 46 s+='c'; 47 for(int i=n-k+3;i<n;i++) 48 s+=char(s[i-1]+1); 49 cout<<s; 50 } 51 return 0; 52 }
1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int mod=1000000007; 5 int ql(int x,int y) 6 { 7 int re=1; 8 while(y!=0) 9 { 10 if(y&1) re=re*x%mod; 11 x=((x%mod)*(x%mod))%mod; 12 y>>=1; 13 } 14 return re; 15 } 16 signed main() 17 { 18 freopen("castle.in","r",stdin); 19 freopen("castle.out","w",stdout); 20 int n,k; 21 cin>>n>>k; 22 n=n%mod; 23 k=k%mod; 24 cout<<(ql(k,k-1)%mod)*(ql(n-k,n-k)%mod)%mod; 25 return 0; 26 }
1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int mod=1000000007; 5 int f[5005][5005]; 6 int n,a,b,k; 7 void add(int&a,int b) 8 { 9 int tmp=a+b; 10 if(tmp>=mod) 11 a=tmp-mod; 12 else if(tmp<0) 13 a=tmp+mod; 14 else 15 a=tmp; 16 } 17 signed main() 18 { 19 freopen("lift.in", "r", stdin); 20 freopen("lift.out", "w", stdout); 21 cin>>n>>a>>b>>k; 22 for(int i=a;i<=n;i++) 23 f[0][i]=1; 24 for(int s=1;s<=k;s++) 25 { 26 for(int i=1;i<=n;i++) 27 { 28 if(i==b) 29 f[s][i]=f[s][i-1]; 30 else 31 { 32 f[s][i]=f[s][i-1]; 33 if(i<b) 34 { 35 int w; 36 if((i+b)%2==0) 37 w=(i+b)/2-1; 38 else 39 w=(i+b)/2; 40 add(f[s][i],f[s-1][i-1]); 41 add(f[s][i],f[s-1][w]); 42 add(f[s][i],-f[s-1][i]); 43 } 44 else 45 { 46 int w=(i+b)/2; 47 add(f[s][i],f[s-1][n]); 48 add(f[s][i],f[s-1][i-1]); 49 add(f[s][i],-f[s-1][w]); 50 add(f[s][i],-f[s-1][i]); 51 } 52 } 53 } 54 } 55 cout<<f[k][n]; 56 return 0; 57 }
下午
题解
标签:tmp,8.4,记录,int,long,re,做题,freopen,mod From: https://www.cnblogs.com/wyh0721/p/17607967.html