洛谷P1025 数的划分
来源:互联网 发布:js时间戳转换工具 编辑:程序博客网 时间:2024/06/06 02:34
题目描述
将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序)。
例如:n=7,k=3,下面三种分法被认为是相同的。
1,1,5; 1,5,1; 5,1,1;
问有多少种不同的分法。
输入输出格式
输入格式:n,k (6<n<=200,2<=k<=6)
输出格式:一个整数,即不同的分法。
输入输出样例
输入样例#1:
7 3
输出样例#1:
4
说明
四种分法为:1,1,5;1,2,4;1,3,3;2,2,3;
一道简单的搜索题,虽然卡了我 30min+ 。。。
还是看了题解才会的。。。
吃枣药丸。。。
附代码:
#include<iostream>#include<algorithm>#include<cstdio>using namespace std;int n,k;long long s=0;void dfs(int x,int m,int l){if(x==k){if(m==n)s++;return;}for(int i=l;i*(k-x)+m<=n;i++)dfs(x+1,m+i,i);}int main(){scanf("%d%d",&n,&k);dfs(0,0,1);printf("%lld\n",s);return 0;}
阅读全文
0 0
- 洛谷 P1025 数的划分
- 洛谷 P1025 数的划分
- 洛谷 P1025 数的划分
- 洛谷 P1025 数的划分
- 洛谷 P1025 数的划分
- 洛谷P1025 数的划分
- P1025 数的划分
- P1025 数的划分
- |洛谷|递推|P1025 数的划分
- 洛谷 P1025 [NOIP2001 T2] 数的划分
- 【搜索】洛谷 P1025 数的划分
- luogu【P1025】数的划分
- P1025 数的划分(洛谷)DFS或者DP
- Luogu-P1025数的划分(dp)
- 洛谷P1025 数的划分(题目来源https://www.luogu.org/problem/show?pid=1025)
- 洛谷 P1205数的划分
- 洛谷1025 数的划分
- 【洛谷1025 数的划分】【搜索】
- 用Construct2再制作游戏
- K近邻算法详解
- 【Java.NIO】Selector,及SelectionKey
- MyBatis 参数处理
- 关于Quartus II工程综合时间过长问题的解决
- 洛谷P1025 数的划分
- Bootstrap简洁、直观、强悍的前端开发框架
- 企业级SVN使用方法
- HDU 1719 Friend
- g++基本用法
- Vue2 封装的 Quill 富文本编辑器组件 Vue-Quill-Editor
- 面试问题总结
- 【项目实战】---统计逗号隔开的字符串的数量
- Github账号怎么添加SSH keys