A
B
C
//题目给出n,表示n个硬币,能够凑成所有0~m的数,并且这n个硬币的和是m
//那么定义撞塌dp[i][j][k],i代表硬币数,j代表能表示1~j的数,k表示硬币中最大的数
#include<iostream>
using namespace std;
typedef long long LL;
const LL mod=2*1e9+7;
const int maxn=200+5;
LL f[maxn][maxn][maxn];
int main()
{
f[1][1][1]=1;
for(int i=1;i<=200;i++){
for(int j=1;j<=200;j++){
for(int k=1;k<=200;k++){
if(!f[i][j][k]) continue;
for(int add=k;add+j<=200&&add<j+2;add++){
f[i+1][j+add][add]+=f[i][j][k];
f[i+1][j+add][add]%=mod;
}
}
}
}
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
LL result=0;
for(int i=1;i<=m;i++)
result=(result+f[n][m][i])%mod;
cout<<result<<endl;
}
return 0;
}
D
E
#include<iostream>
using namespace std;
const int maxn=200000+5;
char s[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
scanf("%s",s);
int len=0;
long long count=0;
for(int i=0;i<n;i++){
if(s[i]=='6') len++;
else{
count+=(long long)(len+1)*len/2;
len=0;
}
}
if(len) count+=(long long)(len+1)*len/2;
printf("%lld\n",count);
}
return 0;
}
F
G
H
#include<iostream>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
struct Matrix{
int m[2][2];
}base,ans;
Matrix multi(Matrix a,Matrix b)
{
Matrix tmp;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
tmp.m[i][j]=0;
for(int k=0;k<2;k++){
tmp.m[i][j]=(tmp.m[i][j]+1LL*a.m[i][k]*b.m[k][j])%mod;
}
}
}
return tmp;
}
LL Fibonacci(LL n)
{
ans.m[0][0]=ans.m[1][1]=1;ans.m[0][1]=ans.m[1][0]=0;
base.m[0][0]=base.m[0][1]=base.m[1][0]=1;base.m[1][1]=0;
while(n)
{
if(n&1)
ans=multi(ans,base);
base=multi(base,base);
n>>=1;
}
return ans.m[0][0];
}
int main()
{
LL n;
while(scanf("%lld",&n)&&n){
printf("%lld\n",Fibonacci(n));
}
return 0;
}
I
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
LL num[maxn];
int main()
{
int n;
LL k;
while(~scanf("%d%lld",&n,&k))
{
for(int i=0;i<n;i++) scanf("%lld",&num[i]);
sort(num,num+n);
int pos=0,count=0;;
for(int i=0;i<n;i++)
{
LL tmp=num[i]+k;
while(num[pos]<tmp&&pos<n) pos++;
if(num[pos]==tmp){
int pos1=pos;
while(num[pos1]==tmp&&pos<n) {pos1++;count++;}
}
}
printf("%d\n",count);
}
return 0;
}
J
#include<iostream>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int x,count=0;
for(int i=0;i<n;i++) {scanf("%d",&x);if(x%2==1) count++;}
printf("%d\n",count);
}
return 0;
}
K
#include<iostream>
using namespace std;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
int result=1;
int base=a;
while(b)
{
if(b&1) result=(1LL*result%mod*base%mod)%mod;
base=(1LL*base*base%mod%mod)%mod;
b>>=1;
}
return result;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
cout<<pow_mod(m,n)<<endl;
}
return 0;
}
L