UVALive 6661 解题心得

原题:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4673

我的代码:

#include<iostream>
#include<cstdio>
using namespace std;

int n, k, sum;
int cnt = 0;
int depth=0;

void dfs(int dep, int cur_num, int cur_sum)
{
    //depth++;
     if (cur_sum == sum)        return;
    for (int i = cur_num; i <= n; i++)
    {
        if (cur_sum+i>sum)            return;
        if (cur_sum+i == sum&&dep==k)
        {
            cnt++;    return;
        }
        dfs(dep + 1, i + 1, cur_sum + i);
    }
}

int main()
{
    while (cin >> n >> k >> sum&&n != 0)
    {
        depth = 0;
        cnt = 0;
        dfs(1, 1, 0);
        cout << cnt << endl;
    }

    return 0;
}
时间: 2024-10-08 11:13:03

UVALive 6661 解题心得的相关文章

第四章学习小结 串的模式匹配 解题心得体会

串的模式匹配 解题心得体会 关于串,模式匹配是其一个很重要的问题.针对这个问题,书上讲了两种模式匹配的算法,即BF算法和KMP算法,下面针对这两种算法的实现谈谈我的心得. 一.BF算法的探索 [错误代码1] #include<iostream> #include<string.h> using namespace std; typedef struct{ char ch[1000002]; int length; }SString; void Index_BF(SString S,

UVALive - 2519 Radar Installation 解题心得

原题: Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distanc

括号配对问题——解题心得

Description You are given a string consisting of parentheses () and []. A string of this type is said to be correct: (a)if it is the empty string (b)if A and B are correct, AB is correct, (c)if A is correct, (A ) and [A ] is correct. Write a program

wechall.net/stegano 解题心得

最近迷上了 www.wechall.net 网站,里面都是些与计算机相关的题目挑战.题目又分很多类型,例如:加密与解密.隐写术.网络攻防.趣味编程.数学逻辑等.题目有的简单,有的很难,需要一些知识和技巧.与其他题目挑战的网站不同的是,在其他类似性质的网站注册的用户可以绑定到 WeChall 网站,然后 WeChall 提供排名信息,而且也分得很细,什么按总分全球排名.什么在自己国家的排名.什么解答某种语言网站题目的排名等.可以从解题的人数判断题目的难易程度,有兴趣的朋友可以去注册,解题中也能学到

[UVALive 6661 Equal Sum Sets] (dfs 或 dp)

题意: 求从不超过 N 的正整数其中选取 K 个不同的数字,组成和为 S 的方法数. 1 <= N <= 20  1 <= K<= 10  1 <= S <= 155 解题思路: DFS: 因为N,K.S的范围非常小.直接DFS就可以. /* ID: [email protected] PROG: LANG: C++ */ #include<map> #include<set> #include<queue> #include<

Ducci Sequence 解题心得

原题贴上 A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a2|,| a2

HDU 4627 The Unsolvable Problem 解题心得

原题: Description There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <= n <= 10 9).We should find a pair of positive integer a, b so that a + b = n and [a, b

USACO Greedy Gift Givers 解题心得

本题算法不难想出,但是中间还是出现了一些问题. 开始的时候是#11:Execution error,后来把普通的数组改成动态数组后问题消失. 后来又出现了Execution error: Your program had this runtime error: Illegal file open (/dev/tty). 随后google解决方案,多数都是数组开小了.遂开大数组,无效. 突然意识到很有可能是低级错误,于是检查代码. 发现写了个 for(int i = 0; i < n2 ; i++

UVa 1647 - Computer Transformation 解题心得

这个题目.... 想上题意 10935 Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the to