UVALive 6661
来源:互联网 发布:自助发稿源码 编辑:程序博客网 时间:2024/05/23 13:58
题目链接:http://vjudge.net/problem/viewProblem.action?id=49406
思路:
题意:根据给出的n,k,s求出n个数每个数都不大于k,和为s的序列(n个数每个都不同)的总情况数。
思路:
利用dfs递归。
代码:
#include<cmath>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int n, k, s;int cnt = 0;void dfs(int sum, int x, int depth) { if (sum > s) return ; if (k - 1 == depth) { if (sum == s) cnt++; return ; } for (int i = x + 1; i <= min(n, s - sum); i++) dfs(sum + i, i, depth + 1);}int main () { while(scanf("%d%d%d", &n, &k, &s)) { if (n + k + s == 0) break; cnt = 0; for (int i = 1; i <= n; i++) { dfs(i, i, 0); } printf("%d\n", cnt); }}
1 0
- UVALive 6661
- UVALive 6661
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- SVN更新异常
- 机器学习-训练模型的保存与恢复(sklearn)
- hdu 1754 线段树(首)
- 判断两颗二叉树是否相同
- 华为 OJ 字符个数统计
- UVALive 6661
- 2015年多校联合训练第四场(Olympiad)hdu5327
- java concurrent并发详解
- TCP/IP概述
- hdu 5290 Bombing plan(树形dp)
- 剑指offer面试题36数组中的逆序对数
- 1004:Let the Balloon Rise
- CXF开发RESTFUL的实例练习
- C语言深度解剖——读书笔记-1、关键字