NOOJ927The partial sum problem
来源:互联网 发布:网络代销商 编辑:程序博客网 时间:2024/04/29 02:30
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=927
这也算是个0-1背包的思想的吧。加上剪枝。
代码:
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int n,k;int a[25];bool dfs(int cur,int sum){ if(sum > k) return false; if(sum == k) return true; if(cur == n) return sum == k; if(dfs(cur + 1,sum)) return true; if(dfs(cur + 1,sum + a[cur])) return true;}int main(){ while(~scanf("%d",&n)) { for(int i = 0; i < n; ++i) scanf("%d",&a[i]); scanf("%d",&k); if(dfs(0,0)) printf("Of course,I can!\n"); else printf("Sorry,I can't!\n"); }}
0 0
- NOOJ927The partial sum problem
- NYOJ927The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- The partial sum problem
- NYOJ927 The partial sum problem
- NYOJ The partial sum problem
- nyoj927The partial sum problem(DFS)
- DFS-The partial sum problem
- NYOJ927 The partial sum problem
- The partial sum problem 搜索
- NYOJ 927 The partial sum problem
- nyoj 927 The partial sum problem
- python 第一天
- 杭州--4.14
- Java三大主流框架的技术起源
- FZU 2140Forever 0.5
- 《现代操作系统(中文第三版)》课后习题——第一章 绪论
- NOOJ927The partial sum problem
- IDEA内存溢出解决办法
- 四六级应试技巧(经典版)
- HDU 5122 K.Bro Sorting
- lightoj 1021 - Painful Bases 【数位dp 状压】
- perl中split分割字符串用法坑人的一些细节!!
- python学习12-算法
- poj 2139 floyd算法
- mysql常用存储引擎