牛客-模拟、枚举与贪心 2022.10.19

[NOIP2007]Hanoi双塔问题

递推问题,但高精度(因为太麻烦所以python)

k=int(input())
a = 0
b = 0
for i in range(1, k + 1):
    b = a + pow(2, i)
    a = b
print(b)

方块与收纳盒

递推,斐波那契数列

#include<bits/stdc++.h>
using namespace std;
long long res[120];
int main() {
    int t;
    cin >> t;
    res[1] = 1, res[2] = 2;
    for(int i = 3; i <= 100; i++)
        res[i] = res[i - 1] + res[i - 2];
    while(t--) {
        int n;
        cin >> n;
        cout << res[n] << endl;
    }
    return 0;
}

I love you

递归做法。用res[i]表示iloveyou匹配了前i个的字符的子序列数,当遇到第i个字符,则之前匹配了前i-1个的字符的子序列都可以变为匹配了前i个的字符的子序列,即res[i]=res[i]+res[i-1]

#include <bits/stdc++.h>
using namespace std;
const int MOD = 20010905;
char c, str[8]= {'i','l','o','v','e','y','o','u'};
int res[8];
int main() {
    res[0]=1;
    while(~scanf("%c",&c)) {
        for(int i = 0 ; i < 8; i++) {
            if(c == str[i] || c == str[i] - 32)
                res[i + 1] = (res[i + 1] + res[i]) % MOD;
        }
    }
    cout << res[8] << endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值