Educational Codeforces Round 16 E. Generate a String

题解:

简单的递推

n为偶--->n/2

n为奇---->n/2,n/2+1

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200100;
const int mod=1e9+7;
const int INF=1e9;

LL x,y,n;

LL DP(int m)
{
    if(m==0) return 0;
    if(m==1) return x;
    if(m&1) return min(DP(m-1),DP(m+1))+x;
    return DP(m/2)+min(x*m/2,y);
}

int main()
{
    cin>>n>>x>>y;
    cout<<DP(n)<<endl;
}
时间: 2024-08-26 16:01:53

Educational Codeforces Round 16 E. Generate a String的相关文章

Educational Codeforces Round 16

A. King Moves water.= =. 1 #include <cstdio> 2 int dx[] = {0,0,1,1,1,-1,-1,-1}; 3 int dy[] = {1,-1,0,1,-1,0,1,-1,0}; 4 #define judge(x,y) x >= 1 && x <= 8 && y >= 1 && y <= 8 5 int main() 6 { 7 char t; 8 int x, y,

Educational Codeforces Round 16 A B C E

做题太久也有点累了..难题不愿做 水题不愿敲..床上一躺一下午..离下一场div2还有点时间 正好有edu的不计分场 就做了一下玩玩了 D是个数学题 F是个AC自动机 都没看明白 留待以后补 A 给出一个8x8棋盘中国王的位置 问国王有多少移动方式 判断输出就可以了 B 给出n个x轴上的数 找出一个数 使其到其他所有数的距离和最小 输出这个数的值 其实这道题是见过的 想法是 先排序 维护一个res 初始值是从最小的数到其他数的距离和 之后每次向右移动 这时候 res会减去右边点数*两点距离差 加

Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16

传送门 Find an n?×?n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n(1?≤?n?≤?49). Output Print n lines with n integers. All the integers should be dif

Educational Codeforces Round 16 B

Description You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line. The second li

Educational Codeforces Round 16 C

Description Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the integers shou

Educational Codeforces Round 25 F. String Compression(kmp+dp)

题目链接:Educational Codeforces Round 25 F. String Compression 题意: 给你一个字符串,让你压缩,问压缩后最小的长度是多少. 压缩的形式为x(...)x(...)  x表示(...)这个出现的次数. 题解: 考虑dp[i]表示前i个字符压缩后的最小长度. 转移方程解释看代码,这里要用到kmp来找最小的循环节. 当然还有一种找循环节的方式就是预处理lcp,然后通过枚举循环节的方式. 这里我用的kmp找的循环节.复杂度严格n2. 1 #inclu

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l