Codeforces Round #247 (Div. 2) ABC
Codeforces Round #247 (Div. 2)
http://codeforces.com/contest/431
代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431
A - Black Square
题意:
Jury玩别踩白块,游戏中有四个区域,Jury点每一个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里。
分析:
模拟水题..
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: a.cpp
* Create Date: 2014-05-21 23:33:25
* Descripton:
*/ #include <cstdio>
#include <iostream>
#include <string>
using namespace std; int a[5], ans;
string s; int main()
{
for (int i = 1; i <= 4; i++)
cin >> a[i];
cin >> s;
for (int i = 0; i < s.length(); i++)
ans += a[s[i] - '0'];
cout << ans << endl;
return 0;
}
B - Shower Line
题意:
5个学生排队,某一个排队方式的每个情况下,第2i-1个人和第2个人会交谈。交谈时,第i和第j个人的交谈会产生g[i][j] + g[j][i]的欢乐(搞基)值,求中最大的欢乐值。
分析:
刚開始还以为人数没定,犹豫了一会...
直接用next_permutation暴力,5!是能够接受的。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: b.cpp
* Create Date: 2014-05-21 23:43:23
* Descripton:
*/ #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 5;
char ch;
int g[N][N], mmax;
int a[5] = {0, 1, 2, 3, 4}; int main()
{
int i = 0, j = 0;
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
scanf("%d", &g[i][j]);
for (int i = 0; i < 5; i++)
for (int j = i + 1; j < 5; j++) {
g[j][i] = g[i][j] = g[i][j] + g[j][i];
}
do {
mmax = max(mmax, g[a[0]][a[1]] + g[a[1]][a[2]] + g[a[2]][a[3]] * 2 + g[a[3]][a[4]] * 2);
} while (next_permutation(a, a + 5));
cout << mmax << endl;
return 0;
}
C - k-Tree
题意:
一颗无限的k-tree,定义例如以下:
每一个节点都有k个分支,第i个分支的边的权值为i。
问在k-tree中有多少条路径,里面至少有一条边权值不小于d,且路径边的和为n。
分析:
比赛时没敲出来(太弱orz),赛后发现有个地方错了...
这题能够用dp,由于是无限的树,所以根节点下来和每一个节点下来是一样的,可是转移为子问题还须要一个因素,就是条件限定边必须<=d,所以我们能够再开一维存放是否须要条件限定。
详细看代码...
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: c.cpp
* Create Date: 2014-05-22 00:20:28
* Descripton:
*/ #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll; const int N = 110;
const int MOD = 1e9 + 7;
ll D[N][2];
int n, d, k; ll dp(int r, bool b)
{
if (D[r][b] != -1)
return D[r][b];
if (r == 0)
return D[r][b] = b;
D[r][b] = 0;
for (int i = 1; i <= min(r, k); i++)
if (b || i >= d)
D[r][b] = (D[r][b] + dp(r - i, 1)) % MOD;
else
D[r][b] = (D[r][b] + dp(r - i, 0)) % MOD;
return D[r][b];
} int main()
{
memset(D, -1, sizeof(D));
scanf("%d%d%d", &n, &k, &d);
cout << dp(n, 0) << endl;
return 0;
}
Codeforces Round #247 (Div. 2) ABC的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #313 (Div. 2) ABC
A http://codeforces.com/contest/560/problem/A 推断给出的数能否组成全部自然数. 水题 int a[1010]; bool b[1000010]; int ...
- Codeforces Round #247 (Div. 2) B - Shower Line
模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
- Codeforces Round #247 (Div. 2)
A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is== ...
- Codeforces Round #247 (Div. 2) C题
赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...
- Codeforces Round #247 (Div. 2) C. k-Tree (dp)
题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...
- [Codeforces Round #247 (Div. 2)] A. Black Square
A. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- Codeforces Round #419 (Div. 2) ABC
python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...
随机推荐
- 函数参数 f_arg, *args, **kwargs
当需要给函数传参时,可以通过运用不同的形参来传递,达到参数不同的使用目的. 简单来说:f_arg就是传递的第一个参数,类似于C++中的普通参数: *args 传递的是一个参数的list: **kwar ...
- LINUX内核中的机制OOM
[概念] LINUX内核中有一个机制叫做OOM killer(Out Of Memery killer) 该机制监控内存占用过大,尤其是瞬间消耗大量内存的进程, 为了防止内存被耗尽,所以OOM kil ...
- Java显式锁学习总结之五:ReentrantReadWriteLock源码分析
概述 我们在介绍AbstractQueuedSynchronizer的时候介绍过,AQS支持独占式同步状态获取/释放.共享式同步状态获取/释放两种模式,对应的典型应用分别是ReentrantLock和 ...
- ASPLOS'17论文导读——SC-DCNN: Highly-Scalable Deep Convolutional Neural Network using Stochastic Computing
今年去参加了ASPLOS 2017大会,这个会议总体来说我感觉偏系统和偏软一点,涉及硬件的相对少一些,对我这个喜欢算法以及硬件架构的菜鸟来说并不算非常契合.中间记录了几篇相对比较有趣的paper,今天 ...
- lr场景运行报错的解决方法
- poj1573 Robot Motion(DFS)
题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...
- GNU Wget 1.19.4 for Windows
资源地址:https://eternallybored.org/misc/wget/ 然后将工具目录加入环境变量
- [Codeforces995C]Leaving the Bar 瞎搞
大致题意: 给出平面上n个向量,对于每个向量可以选择正的V或负的-V,求按照选择的向量走完,最后距离原点<=1.5*1e6的一个选择方案 非正解!!!!!!!!!! 先按距离原点距离由远到近贪心 ...
- POJ 2019 Cornfields [二维RMQ]
题目传送门 Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7963 Accepted: 3822 ...
- Android之 内容提供器(2)——创建自己的内容提供器将数据共享出去
创建自己的内容提供器非常简单,只需要新建一个类继承ContentProvider类,通过实现ContentProvider的增删改查的方法向内容提供器中增删数据. 1 ContentProvider简 ...