【JZOJ 4314】【NOIP2015模拟11.4】老司机
2018-01-30 21:11
417 查看
问题描述
输入
输出
样例输入
4
1 3 6 6
样例输出
3
1 2 3
算法讨论
注意到1,2,4,8,16,32总是一个可行解,所以答案不会超过6。爆枚答案是什么即可。
事实上字典序最小的通解是1,2,3,6,13,25。
输入
输出
样例输入
4
1 3 6 6
样例输出
3
1 2 3
算法讨论
注意到1,2,4,8,16,32总是一个可行解,所以答案不会超过6。爆枚答案是什么即可。
事实上字典序最小的通解是1,2,3,6,13,25。
#include <cstdio> using namespace std; #define maxn 5656 #define maxlongint 2147483647 int cost[maxn],c[maxn],c1[maxn],t[maxn],f1[maxn]; int b[7]={0,4,8,16,32,64,128}; bool f[maxn]; int n,k,l,maxc,maxk,mindep=maxlongint; bool flag; bool check() { for (int i=1;i<=n;i++) if (f1[cost[i]]==0) return 0; return 1; } int dfs(int dep,int last) { if (check() && dep-1<mindep) { mindep=dep-1; for (int i=1;i<=maxk;i++) c1[i]=c[i]; return 0; } if (dep>maxk || dep>mindep) return 0; for (int i=last;i<=32;i++) { int x=0; t[++l]=i; f1[t[l]]++; for (int j=1;j<l;j++) { t[j+l]=t[j]+t[l]; f1[t[j+l]]++; x++; } l+=x; c[dep]=i; dfs(dep+1,i); c[dep]=0; for (int j=l;j>=l-x;j--) { f1[t[j]]--; t[j]=0; } l-=(x+1); } } int main() { freopen("driver.in","r",stdin); freopen("driver.out","w",stdout); scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",&cost[i]); if (!f[cost[i]]) { f[cost[i]]=1; maxk++; } if (maxk>6) maxk=6; if (cost[i]>maxc) maxc=cost[i]; } dfs(1,1); printf("%d\n",mindep); for (int i=1;i<=mindep;i++) printf("%d ",c1[i]); fclose(stdin); fclose(stdout); return 0; }
相关文章推荐
- 【NOIP2015模拟11.4】电话线铺设 jzoj 4313 最小生成树+树链剖分
- 【JZOJ 4309】【NOIP2015模拟11.4】刷题计划 刷题计划
- 【JZOJ 4310】【NOIP2015模拟11.4】最优交换(贪心)
- Day 5 jzoj4309. 【NOIP2015模拟11.4】刷题计划
- Day 5 jzoj 4311. 【NOIP2015模拟11.4】统一天下
- Day 6 jzoj 4312. 【NOIP2015模拟11.4】格点统计
- Day 5 jzoj 4310. 【NOIP2015模拟11.4】最优交换
- NOIP2015模拟11.4总结
- JZOJ4307. 【NOIP2015模拟11.3晚】喝喝喝
- jzoj4216. 【NOIP2015模拟9.12】平方和
- JZOJ 4307. 【NOIP2015模拟11.3晚】喝喝喝
- JZOJ 4294【NOIP2015模拟11.2】复制&粘贴2
- JZOJ 4295【NOIP2015模拟11.2】愉快的logo设计
- JZOJ.4300[NOIP2015模拟11.3]装饰大楼 解题报告
- JZOJ 4296【NOIP2015模拟11.2】有趣的有趣的家庭菜园
- JZOJ.4301[NOIP2015模拟11.3]备用钥匙 解题报告
- [jzoj]4216. 【NOIP2015模拟9.12】平方和【线段树二分+码量】
- JZOJ 4302【NOIP2015模拟11.3】IOIOI卡片占卜
- jzoj. 4298. 【NOIP2015模拟11.2晚】我的天
- JZOJ 4298. 【NOIP2015模拟11.2晚】我的天