The King
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7499   Accepted: 4060

Description

Once upon a time in a country far away lived a king and he had a big kingdom. He was a very clever king but he had one weakness -- he could count only up to three.
Nevertheless, he did not consider this to be a really great drawback, since he had a lot of wizards who could count up to one hundred (and some of them, people said, even up to one thousand), so it was all right. But one day the grief came to the kingdom as the outnumbering barbarians started to approach from all sides. And the king then had to make the most important decision in his life. He had to choose which of his sons to make generals that he would send to the borders of the country to lead the army.
However, the king knew that though some of his sons were clever, just like he was, some of them were quite stupid and could only lower army spirits with their wrong decisions. More precisely, he knew about each of his sons his mental potential -- an integer number ranging from minus three to three (remember, that the king could count only up to three). He also knew that the chance of his army defeating barbarians was proportional to the sum of some powers of mental potentials of those of his sons that he would make generals (the power exponent was a positive integer number, the same for all his sons and not exceeding three either). Thus he had to choose such a combination of his sons to lead
the army, that this sum would be maximal possible.
However, the king himself could not make all apropriate calculations since, for example, the second power of the number not exceeding three (which is its square) could be greater than three, and therefore he asked you, his most intellegent wizard, to solve this problem.

Input

The first line of the input file contains the number of the sons of the king (integer number less or equal to one hundred). The second line contains the positive integer number not exceeding three, the exponent in the formula used to calculate the chance of defeating barbarians. The third line contains the list of mental potentials of king’s sons -- all integer numbers, not greater than three by their absolute value.

Output

Output the only number -- the maximal possible chance of defeating barbarians measured as the sum described.

Sample Input

3
3
2 -1 1

Sample Output

9

Hint

In the example above the king should choose his first and third sons to be the generals. In this case the chance to defeat barbarians, which is the sum of cubes of mental potentials of these sons, is eight plus one, that is nine.

Source

Northeastern Europe 2002, Northern Subregion
题目链接:http://poj.org/problem?id=2209
题解:以前挂的一些贪心的题没有做,有位大佬叫我写下题解,有些看不懂题意,我恭敬不如从命了,写点吧,算是复习下贪心吧!
题意:比较难理解,第一个数是数列的长度,第二个数字是指数,第三行是数列,即真数。从数列中选择任意多个,使得他们每个求幂再求和最大。
下面给出AC代码:
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
int a[];
int b[];
while(scanf("%d",&n)!=EOF)
{
scanf("%d",&m);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int sum=,ans=;
for(int i=;i<n;i++)
{
for(int j=;j<=m;j++)
sum*=a[i];
if(sum>)
ans+=sum;
sum=;
}
printf("%d\n",ans);
}
return ;
}

POJ 2209 The King(简单贪心)的更多相关文章

  1. POJ 2209 The King#贪心

    (- ̄▽ ̄)-*  水 //水题:潜力^e为正数(e为2时都可以)的儿子都可以去上战场了, //英文要看懂,exponent指数,不超过3的正数 #include<iostream> #i ...

  2. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  3. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  4. CDOJ 1502 string(简单贪心)

    题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...

  5. ACM_发工资(简单贪心)

    发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...

  6. ACM_Ruin of Titanic(简单贪心)

    Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...

  7. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  8. POJ 2370 Democracy in danger(简单贪心)

    Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 25 ...

  9. POJ 2260 Error Correction 模拟 贪心 简单题

    Error Correction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6825   Accepted: 4289 ...

随机推荐

  1. springMVC(4)---生成excel文件并导出

    springMVC(4)---生成excel文件并导出 在开发过程中,需要将数据库中的数据以excel表格的方式导出. 首先说明.我这里用的是Apache的POI项目,它是目前比较成熟的HSSF接口, ...

  2. iOS知识点、面试题 之三

    最近面试,发现这些题 还不错,与大家分享一下,分三文给大家: 当然Xcode新版本区别,以及iOS新特性 Xcode8 和iOS 10 在之前文章有发过,感兴趣的可以查阅: http://www.cn ...

  3. JS画图之七【时钟】

    样例:http://www.zhaojz.com.cn/demo/draw12.html 依赖:圆 一.定义对象:针 //定义钟表指针 //dotClock 原点 //len 指针长度 functio ...

  4. C# Split用法

    1.用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray= ...

  5. python学习中的一些“坑”

    一.交互列表元素时,需要注意的坑. 例如: array=[4,5,9,8,10,8,4,0,3,4]  最大的值与第一个元素交换,最小的值与最后一个元素交换 # -*- coding: UTF-8 - ...

  6. 轮播插件、原生js编写,弄懂这个,基本上各种轮播都可以自己写了

    直接上代码了: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  7. Disruptor并发框架(一)简介&上手demo

    框架简介 Martin Fowler在自己网站上写了一篇LMAX架构的文章,在文章中他介绍了LMAX是一种新型零售金融交易平台,它能够以很低的延迟产生大量交易.这个系统是建立在JVM平台上,其核心是一 ...

  8. 【开源】AspnetCore 2.0 自动API文档生成组件,支持protobuffer

    本文地址 http://www.cnblogs.com/likeli/p/8204054.html 关于 API文档自动生成,用于对APP端的开发帮助文档生成,默认ProtoBuffer传输格式. 本 ...

  9. PHP call_user_func

    <?php function my_call_back_function(){ echo "hello world!"; } class MyClass{ static fu ...

  10. Spring之DAO二

    上一篇算是把JdbcDaoSupport的使用演示了一下,这篇主要是演示MappingSqlQuery.SqlUpdate.SqlFunction的使用以及Spring的事务管理. 一.Mapping ...