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的更多相关文章

  1. 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 ...

  2. Codeforces Round #313 (Div. 2) ABC

    A http://codeforces.com/contest/560/problem/A 推断给出的数能否组成全部自然数. 水题 int a[1010]; bool b[1000010]; int ...

  3. Codeforces Round #247 (Div. 2) B - Shower Line

    模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  4. Codeforces Round #247 (Div. 2)

    A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is== ...

  5. Codeforces Round #247 (Div. 2) C题

    赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...

  6. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  7. [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 ...

  8. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  9. Codeforces Round #419 (Div. 2) ABC

    python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...

随机推荐

  1. JSOI 2017 Round 1滚粗记

    day0 到常州一中报道,吃了午饭,好像这次有小火锅. 然后下午听JYY讲线性规划...好神啊. 晚上去试机,机子上没有npp,只有linux下的codeblocks,敲起来一顿一顿的...后来被迫使 ...

  2. 利用Google API生成二维码

    什么是二维码:二维码是二维条形码的一种,可以将网址.文字.照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容.读取方式:利用30万画素 ...

  3. 转:google测试分享-GTA

    原文: http://blog.sina.com.cn/s/blog_6cf812be0102viuh.html 上一次分享了google测试分享-分层测试,有很多自动化测试的策略和实施都要有一个重点 ...

  4. (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现

           架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用        优势:       ...

  5. Python+Selenium 自动化实现实例-实现文件下载

    #coding=utf-8 from selenium import webdriver #实例化一个火狐配置文件 fp = webdriver.FirefoxProfile() #设置各项参数,参数 ...

  6. hdu 5202(DFS)

    Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  7. [转]Java中堆和栈创建对象的区别

    转载自http://blog.csdn.net/hbhhww/article/details/8152838 栈与堆都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序 ...

  8. CSU 1355 地雷清除计划

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1355 好题,根本想不到是网络流. 模型如图: 假想从右上角到左下角有一条阻拦线,我们就是 ...

  9. fastdfs5.11+centos7.2 按照部署(三)【转载】

    1.测试 前面两篇博文已对FastDFS的安装和配置,做了比较详细的讲解.FastDFS的基础模块都搭好了,现在开始测试下载. 1.1 配置客户端 同样的,需要修改客户端的配置文件: vim /etc ...

  10. Good Bye 2014 E - New Year Domino 单调栈+倍增

    E - New Year Domino 思路:我用倍增写哒,离线可以不用倍增. #include<bits/stdc++.h> #define LL long long #define f ...