您的位置:首页 > 其它

CodeForcesGym 100517I IQ Test

2015-10-10 19:44 295 查看

IQ Test

Time Limit: 2000ms
Memory 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: