SRM478
又是rng_58的神题。。
250pt:
题意:给定一个初始数x,对于这个数可以进行x*4+3,或者x*8+7的操作。最多进行100000次操作
问最少经过几次出现%1000000007 == 0的情况。。
思路:
x*4+3 = (x * 2 + 1) * 2 + 1
x * 8 + 7 = (x * 4 + 3) * 2 + 1
所以我们发现两个操作都可以合并成x * 2 + 1的操作。所以直接模拟30w次*2+1操作。
如果操作y次*2+1那么答案便是(y + 2) / 3,注意y == 1时无解需特判
code:
#line 7 "CarrotJumping.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define M 1000000007
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class CarrotJumping
{
public:
int theJump(int x)
{
for (int i = ; i <= ; ++i){
x = (x * + ) % M;
if (x == && i >= ) return (i + ) / ;
}
return -;
}
};
500pt
题意:有N<=15个杯子,所有杯子的容量都是一样的,为C<50。现在已知每个杯子当前的水量,数量为x的杯子可以卖p[i]的钱。不过在卖之前可以做任意次操作:选两个杯子a和b,把a的水往b倒,知道a空了或者b满了为止。问这些杯子经过操作后,最多一共能卖多少钱。
思路: 如果选中若干个杯子,那么这些杯子的状态便是固定的,因为必须倒到满或者空。
那么集合dp的感觉就很明显了
dp[mask]表示选中mask状态个的被子最多卖多少钱。然后枚举子状态即可。。
code:
#line 7 "KiwiJuice.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair
#define two(i) (1 << i)
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int dp[ << ], cost[ << ];
class KiwiJuice
{
public:
int c, n;
vector<int> b, p;
void calculateCost(int mask){
int v = , bn = ;
for (int i = ; i < n; ++i)
if (two(i) & mask){
v += b[i];
++bn;
}
cost[mask] = p[v % c] + (v / c) * p[c] + p[] * (bn - v / c - );
}
int dfs(int mask){
if (dp[mask] != -) return dp[mask];
dp[mask] = ;
for (int i = mask; i; i = (i-) & mask)
dp[mask] = max(cost[i] + dfs(mask ^ i), dp[mask]);
return dp[mask];
}
int theProfit(int C, vector <int> bottles, vector <int> prices)
{
b = bottles, p = prices;
n = b.size(), c = C;
for (int i = ; i < two(n); ++i)
calculateCost(i);
memset(dp, -, sizeof(dp));
return dfs(two(n) - );
}
};
SRM478的更多相关文章
- [SRM478]RandomApple
题意:有$k$种苹果和$n$个箱子,每个箱子中有一些苹果,先等概率选取$n$个箱子组成集合的非空子集,再从选出的苹果中随机选一个,问每种苹果被选中的概率是多少 设箱子$i$有$cnt_{i,j}$个第 ...
随机推荐
- 在centos7上安装elasticSearch
因为elasticsearch是用java编写的,所以需要先安装JDK: jdk1.8的安装:安装指导 elasticsearch的下载和安装 一.下载elasticSearch 1.下载地址: ht ...
- mysql使用存储过程,自动生成新的表单
use mydb; delimiter // CREATE procedure create_table(In imax int) BEGIN DECLARE `@i` int(11); D ...
- pthon 反转嵌套的list
def rev_recursive(li): try: iterator = iter(li) except TypeError: return li l = [] for item in itera ...
- ES开发的一些坑(一)
一.ES-Hadoop导数据的时候报"Could not write all entries"异常 ES-Hadoop是一个开源的数据导入项目,支持数据从hdfs,hive,sp ...
- java通过接口扩展枚举
package com.hra.riskprice; import com.hra.riskprice.SysEnum.Factor_Type; import com.hra.riskprice.po ...
- Android NDK定位.so文件crash代码位置
参考:http://blog.csdn.net/xyang81/article/details/42319789 问题: QRD8926_110202平台的Browser必现报错.(去年的项 ...
- ubuntu配置ftp server
ubuntu配置ftp server 1. 安装vsftpd sudo apt-get install vsftpd 安装后会自动新建一个用户ftp,密码ftp,作为匿名用户登录的默认用户 sud ...
- python r r+ w w+ rb 文件打开模式的区别
# 只读模式with open ( "file.txt" ,'r' ) as f: for line in f.readlines(): ...
- 【转】再讲IQueryable<T>,揭开表达式树的神秘面纱
[转]再讲IQueryable<T>,揭开表达式树的神秘面纱 接上篇<先说IEnumerable,我们每天用的foreach你真的懂它吗?> 最近园子里定制自己的orm那是一个 ...
- javascript对象的属性,方法,prototype作用范围分析.
用了javascript这么久由于没有系统学习过基础,总是拿来主义. 所以对一些基础知识还是搞不清楚很混乱. 今天自己做个小例子,希望彻底能搞清楚. 注释中对象只例子的对象本身,原型只原型继承对象的新 ...