CodeForcesGym 100517I IQ Test
2015-10-10 19:44
295 查看
IQ Test
Time Limit: 2000msMemory Limit: 262144KB
This problem will be judged on CodeForcesGym. Original ID: 100517I
64-bit integer IO format: %I64d Java class name: (Any)
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 10010; int p[maxn],n; struct A { int val,id; bool operator<(const A &rhs) const { return val < rhs.val; } } a[maxn]; LL dp[maxn]; vector<int>ans[maxn]; int main() { #define NAME "iq" freopen(NAME".in","r",stdin); freopen(NAME".out","w",stdout); while(scanf("%d",&n),n) { for(int i = 1; i <= n; ++i) { scanf("%d",&a[i].val); a[i].id = i; } sort(a + 1,a + n + 1); memset(dp,0x3f,sizeof dp); dp[0] = 0; p[0] = -1; for(int i = 0; i < maxn; ++i) ans[i].clear(); for(int i = 1; i <= n; ++i) { for(int j = 0; j < i; ++j) { LL tmp = dp[j] + (LL)a[i].val*(n - j); if(tmp < dp[i]) { dp[i] = tmp; p[i] = j; } } } printf("%I64d\n",dp ); int group = 0; for(int i = p ; ~i; i = p[i]) ++ group; printf("%d\n",group); int cur = n,cnt = group; while(~p[cur]) { for(int i = cur; i > p[cur]; --i) ans[cnt].push_back(a[i].id); cur = p[cur]; --cnt; } for(int i = 1; i <= group; ++i) { printf("%d",ans[i].size()); for(auto &it:ans[i]) printf(" %d",it); putchar('\n'); } } return 0; }
View Code
相关文章推荐
- Codevs P1018 单词接龙
- 软件测试的分类(上)
- Unity Text 插入图片
- 【已解决】WinPhone模拟器报错:模拟器没法确定来宾虚拟机通信的主机ID地址。某些功能已被禁用
- ArrayList和Vector的区别,HashMap和Hashtable的区别
- mac下查看占用端口
- php利用header函数实现文件下载时直接提示保存
- c语言中static作用的简单概述
- User-Agent
- TreeSet底层数据结构是二叉树
- EditorWindow 和MenuItem
- LeetCode 2 Word Pattern
- fdk-aac-0.1.4编译
- C++中变量存储类型
- 一条直线上N个线段所覆盖的总长度
- Android备忘录
- 第六、七章重点知识点总结
- php header的用法
- Android5.0上WebView的android.content.res.Resources$NotFoundException
- Enable WiX project in Visual Studio 2013