您的位置:首页 > 其它

SRM149 - SRM150(少SRM150-DIV1-LV3)

2013-08-15 01:31 239 查看
SRM 149

DIV2 1000pt

题意:

  对于n个人,第i人有pi的钱。将他们分成不超过四个组,每组统一交费x,对每个人,若他拥有的钱超过x则交费,否则不交费。问最多能使这些人交多少钱。

  1<= n <= 50,0 <= pi <= 1000。

tag:greedy,think

解法:枚举所有分组情况,每组交费x为该组中最小的pi。如果分组不足四组,补足四组,每组均含一个人钱数为0的人。

Ps:感觉自己的代码写得比题解舒服.....

#line 10 "StripePainter.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <set>
#include <queue>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack>

using namespace std;

#define CLR(x) memset(x, 0, sizeof(x))
#define PB push_back
#define SZ(v) ((int)(v).size())
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false)

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;

const double eps = 1e-8;
const double PI = atan(1.0)*4;
const int maxint = 2139062143;

inline int MyMod( int a , int b ) {a = a % b;if (a < 0) a += b; return a;}

string s;
int m[55][55][100];

int ask(int l, int n, char c)
{
int& a = m[l]
[(int)c];

if (!n) return 0;

if (a != -1) return a;
a = maxint;

if (c == s[l]){
a = ask (l+1, n-1, c);
return a;
}

for (int i = 1; i < n; ++ i)
for (int j = 'A'; j <= 'Z'; ++ j)
a = min (a, 1 + ask(l, i, s[l]) + ask(l+i, n-i, c));
a = min (a, 1 + ask(l, n, s[l]));
return a;
}

class StripePainter
{
public:
int minStrokes(string stripes){
s.clear();
s = stripes;
memset (m, -1, sizeof (m));

int size = SZ (s);
for (int i = 0; i < size; ++ i)
for (int j = 0; j + i <= size; ++ j)
for (int k = 'A'-1; k <= 'Z'; ++ k)
m[i][j][k] = 1 + ask(i, j, (char)k);

return (m[0][size][(int)s[0]]);
}
};


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: