Cattle off the sixth game


Number of Questions in Competition D

#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int n, cnt;
int t;
ll a[150009];
void work()
{
    
    

	ll ans = 0;
	bool f = 0;
	for(int i = 1; i <= n; ++i)
	{
    
    
		scanf("%lld", &a[i]);
		if(a[i] == cnt && !f)
		{
    
    
			f = 1;
		}
		else ans += a[i];
	}
	if(n == 2) cout << ans << endl;
	else cout << ans % 11 << endl;
}
int main()
{
    
    
	
	while(~scanf("%d %d",&n, &cnt))
		work();
	return 0;
}

Number of F question combinations

Derivation of Lanzi
Insert picture description here
Insert picture description here

#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s[1010];
ll dp[100010];
int mod=998244353;
ll power(ll a,ll b)
{
    
    
    ll res = 1;
    while(b)
	{
    
    
        if(b & 1) res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}
int main()
{
    
    
	dp[4] = 2;
    ll n;
    //2^(n-2)-或+2*(n/2)+
    cin >> n;
    /*cout<<((power(2,n-2)+(n%8!=0?-1:1)*power(2,n/2)-(n%8!=0?-1:1)*power(2,n/2-1))%mod+mod)%mod;*/
    // 兰子姐姐的写法看不懂
    for(int i = 8; i <= n ; i += 4)
	{
    
    
		dp[i] = power(2, i-2) + power(2, i-4) - 4 * dp[i-4];
	}
	cout << dp[n] << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/cosx_/article/details/114127312