美文网首页
普及组Day2教案

普及组Day2教案

作者: 学无止境1980 | 来源:发表于2019-08-17 22:55 被阅读0次

递归专题

P1157 组合的输出

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n, r, x[25], len;
void work() {
    if (len == r) {
        for (int i=0; i<r; i++) printf("%3d", x[i]);
        printf("\n");
        return;
    }
    int last = len>0 ? x[len-1]+1 : 1;
    for (int i=last; i<=n; i++) { // 保证后面选择的数比前面都大
        x[len++] = i;
        work();
        len--; // 回溯
    }
}
int main() {
    scanf("%d %d", &n, &r);
    work();
    return 0;
}

Luogu P2386 放苹果

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int M, N, x[15], len, sum, K;
void work() {
    if (len == N) {
        if (sum == M) K++;
        return;
    }
    int last = len>0 ? x[len-1] : 0;
    for (int i=last; i<= M-sum; i++) {
        x[len++] = i;
        sum += i;
        work();
        sum -= i;
        len--;
    }
}
int main() {
    int T; scanf("%d", &T);
    while (T--) {
        K = 0;
        scanf("%d %d", &M, &N);
        work();
        printf("%d\n", K);
    }
    return 0;
}

相关文章

  • 普及组Day2教案

    递归专题 P1157 组合的输出 Luogu P2386 放苹果

  • 普及组Day1教案

    首先自己先注册好一个洛谷Luogu的账号,接下来三天都在上面刷题。上课前询问一下学生们有没有在这个网站上注册账号,...

  • 普及组Day3教案

    栈:栈就是先进后出,比如我把数字3、5、2放入栈中,然后第一次从栈中取出来的数字是2,然后取出来的数字是5,这时如...

  • 诲人不倦2018-05-02

    《诲人不倦》教案 语文组骨干教师公开课教案 徐红辉 http://www.edudo.com/85541 【教学目...

  • 杜尔伯特历史分享

    杜尔伯特科技普及(一)。1956年,科学普及协会开始有计划有目的组织开展科学普及活动。各学组、会员工作组利用举办讲...

  • 标题:【2班3组】+Day2真正有效的写作训练法

    标题:【2班3组】+Day2 真正有效的写作训练法 图片: 【学员信息】69-圆心-Day2(我房间的描写) 【作...

  • 开场舞蹈 #普及组#

    题目 Problem Description 在全世界人民的期盼下,2008年北京奥林匹克运动会终于隆重召开了! ...

  • 景泰一中第三十届“双研会”优秀教案作业展评

    1.各教研组按照《景泰一中优秀教案评选标准》、《景泰一中作业批改优秀评选标准》推荐优秀教案和批改优秀作业参...

  • 联动日更 || 72 话说作业检查

    按照学校例行安排,上周六下午,我们学校成立作业、教案检查组对所有教师的作业教案进行了检查。 鉴于要评选...

  • 易效能一阶206期践行学委工作20180612-

    Day2: 学习任务: @所有人 易效能一阶206期15组践行Day2: 今天是线下践行的第二天,我们先热下身 今...

网友评论

      本文标题:普及组Day2教案

      本文链接:https://www.haomeiwen.com/subject/fcklsctx.html