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. 【java】io流之字节输出流:java.io.OutputStream类及子类java.io.FileOutputStream

    package 文件操作; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; impo ...

  2. Python学习日记:day7-----集合

    1.基础数据类型汇总补充 1,list: 在循环一个列表是,最好不能删除列表中的元素. 2,bool 空列表.int:0.空str.空dict.空set--->bool:false 其余为tru ...

  3. magento获取商品的图片

    获取商品的图片主要从catalog_product_entity_media_gallery 表中 该表中各列的属性代表 value_id:记录 ID,可以留空让数据库自动生成. attribute_ ...

  4. 关于spring mybateis 定义resultType="java.util.HashMap"

    关于spring mybateis  定义resultType="java.util.HashMap" List<HashMap<String, Object>& ...

  5. ES6 Proxy和Reflect (上)

    Proxy概述 Proxy用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种"元编程"(meta programming),即对编程语言进行编程. Proxy可以理 ...

  6. PHP与REDIS

    安装 1.一定要搞懂自己php的版本,和环境,今天试一上午,就是因为X86,而我的php环境是X64. 2. 将下载的php_redis.dll和php_igbinary.dll放在php扩展目录中( ...

  7. FPGA浮点数定点化

    因为在普通的fpga芯片里面,寄存器只可以表示无符号型,不可以表示小数,所以在计算比较精确的数值时,就需要做一些处理,不过在altera在Arria 10 中增加了硬核浮点DSP模块,这样更加适合硬件 ...

  8. PS字体倾斜、变形

    整体效果: 学习地址:http://www.wzsky.net/html/Photo/psjc/psc/125890_1.html 第一步新建画布,这个大家必须会,输入文字"基"基 ...

  9. requireJS教程

    目录[-] 使用 RequireJS 优化 Web 应用前端 AMD 简介 传统 JavaScript 代码的问题 AMD 的引入 清单 1. AMD 规范 RequireJS 简介 实战 Requi ...

  10. C# winForm资源文件实现多语言切换

    这是我目前看到过最简单的多语言切换了 操作步驟 介面上的多語 Step1.將表單的Localizable屬性設為True Step2.切換表單的Language屬性為欲使用的語系 設完後會在分頁標籤上 ...