HDU Sum It Up
来源:互联网 发布:电磁场仿真软件 编辑:程序博客网 时间:2024/06/01 23:02
Sum It Up
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 72 Accepted Submission(s) : 45
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
4 6 4 3 2 2 1 15 3 2 1 1400 12 50 50 50 50 50 50 25 25 25 25 25 250 0
Sample Output
Sums of 4:43+12+22+1+1Sums of 5:NONESums of 400:50+50+50+50+50+50+25+25+25+2550+50+50+50+50+25+25+25+25+25+25
#include<iostream>#include<cstdio>#include<algorithm>#include<string.h>int a[13],t,n;bool b[13],bb;using namespace std;int main(){void dfs(int,int);while (scanf_s("%d%d", &t, &n) != EOF){if (t == 0 && n == 0) break;bb = 0;memset(b, 0, sizeof(b));for (int i = 1; i <= n; i++)scanf_s("%d", &a[i]);a[0] = -1;printf("Sums of %d:\n", t);dfs(1,0);if (bb == 0) printf("NONE\n");}return 0;}void dfs(int k,int sum){for (int i = k; i <= n; i++){if (a[i] == a[i - 1] && b[i - 1] == 0) continue;//防止重复选择if (sum + a[i] < t&&b[i]==0){b[i] = 1;dfs(i + 1, sum + a[i]);b[i] = 0;}else if (sum + a[i] == t&&b[i]==0){bb = 1;for (int j = 1; j <= n; j++){if (b[j]){printf("%d+", a[j]);}}printf("%d\n", a[i]);数组非递增,没必要继续往下搜}}}
- HDU:Sum It Up
- Sum It Up HDU
- HDU Sum It Up
- hdu 1258 Sum It Up
- HDU 1258 sum it up
- HDU-1258-Sum It Up
- HDU 1258 Sum It Up
- HDU-1711:Sum It Up
- hdu 1258 sum it up
- HDU 1258 - Sum It Up
- hdu 1258 Sum It Up
- hdu 1258 Sum It Up
- hdu 1258 Sum It Up
- (hdu) 1258 Sum It Up
- HDU 1258 Sum It Up
- HDU 1258:Sum It Up
- hdu-1258 Sum It Up
- hdu 1258 Sum It Up
- 找不到包含 OwinStartupAttribute 的程序集
- BSD许可证
- C#之中的字符串替换方法以及判断是否存在特定子字符串
- Struts2的简单搭建(一)
- MyEclipse如何修改编码如“GBK”“UTF-8”
- HDU Sum It Up
- 2018第三届中国青年健康论坛——生理、心理与教育(CYHF 2018)
- 《SpringCloud微服务实战》学习笔记之服务治理Eureka(单节点)
- 机器学习
- JAVA 一 输出格式,基础知识
- Java虚拟机内存的代的划分
- 初次使用指针
- 免费框架与付费框架之争
- 外汇模拟交易软件B&G GLOBAL MARKETS受到热捧