题目1251:序列分割
来源:互联网 发布:ipad1越狱后安装软件 编辑:程序博客网 时间:2024/06/10 10:09
#include <stdio.h>#include <stdlib.h>#include <string.h> int cmp(const void *a, const void *b) { return (*(int *)a < *(int *)b) * 2 - 1;} int n, A[100], sum;int mark[100], ans, full; int dfs(int cnt, int max, int re, int s) { if (cnt == 0) return 1; if (re == 0) { return dfs(cnt-1, max, max, 0); } int i; for (i=s; i<n; i++) { if (mark[i] || re-A[i] < 0) continue; mark[i] = 1; if (dfs(cnt, max, re-A[i], i+1)) return 1; mark[i] = 0; if (re-A[i] == 0) break; if (max == re) break; //the largest number have try, and failed, cut // not sucess, skip the same number while (A[i+1] == A[i] && i+1<n) i++; } return 0;} int Try(int len) { if (sum % len != 0) return 0; memset(mark, 0, sizeof mark); return dfs(sum/len, len, len, 0);} void Solve() { qsort(A, n, sizeof(int), cmp); int m = A[0]; while (!Try(m)) m++; printf("%d\n", sum/m);} int main(){ int i, j; while (scanf("%d", &n), n) { for (sum=i=0; i<n; i++) scanf("%d", &A[i]), sum+=A[i]; Solve(); } return 0;}/************************************************************** Problem: 1251 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1020 kb****************************************************************/
0 0
- 题目1251:序列分割
- 题目1251:序列分割(DFS+剪枝)
- 九度 题目1251:序列分割
- [省选前题目整理][BZOJ 3675][APIO 2014]序列分割(斜率优化DP)
- PAT 1044. Shopping in Mars (25)(子序列分割问题,题目不错)
- 题目:分割回文串
- 题目:奇偶分割数组
- 解析分割字符串序列
- bzoj-3675 序列分割
- BZOJ 3675 序列分割
- APIO2014序列分割bzoj3675
- bzoj3675: [Apio2014]序列分割
- [BZOJ3675][Apio2014]序列分割
- [BZOJ3675] [Apio2014]序列分割
- bzoj3675【APIO2014】序列分割
- 【APIO2014】序列分割
- 【APIO2014】序列分割(sequence)
- 3675: [Apio2014]序列分割
- 面试干货 for Android(一)
- 如何调试异步加载的js文件
- maven中maven dependencies中依赖出现了问题
- 1081. Rational Sum (20)-PAT甲级
- 数组
- 题目1251:序列分割
- 深入理解布局容器绘制,解决ListView嵌套listview,或者ScrollView嵌套listview,gridview的高度问题解决方法
- dubbo总结(2)——dubbo的使用场景
- 磁盘文件最优存储
- 题目1252:回文子串
- MySQL 5.7.17 免安装版本的安装与配置
- 【BNUOJ】Borrow Classroom
- 手把手git教程(08)--开发分支常用处理流程
- webstorm实用功能