2017.10.23
来源:互联网 发布:淘宝没有盗版书了 编辑:程序博客网 时间:2024/05/21 19:22
CodeForces - 225C
You’ve got an n × m pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
All pixels in each column are of the same color.
The width of each monochrome vertical line is at least x and at most y pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than x or greater than y.
Input
The first line contains four space-separated integers n, m, x and y (1 ≤ n, m, x, y ≤ 1000; x ≤ y).
Then follow n lines, describing the original image. Each of these lines contains exactly m characters. Character “.” represents a white pixel and “#” represents a black pixel. The picture description doesn’t have any other characters besides “.” and “#”.
Output
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
Example
Input
6 5 1 2
.#.
.###.
..
…
.##.#
..
Output
11
Input
2 5 1 1
#
…..
Output
5
Note
In the first test sample the picture after changing some colors can looks as follows:
.##..
.##..
.##..
.##..
.##..
.##..
In the second test sample the picture after changing some colors can looks as follows:
.#.#.
.#.#.
dp
主要是写转移方程
#include<iostream>#include<cstring>using namespace std;char mapp[2000][2000];int a[2000],b[2000];int dp[2000][2];int main (){ int n,m,x,y; while(cin>>n>>m>>x>>y) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(dp,0x3f,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf(" %c",&mapp[i][j]); if(mapp[i][j]=='#') { a[j]++; } else { b[j]++; } } } int i,j; for(i=1;i<=m;i++) { a[i]+=a[i-1]; b[i]+=b[i-1]; } dp[0][0]=0; dp[0][1]=0; for(i=0;i<m;i++) { for(j=x;j<=y;j++) { dp[i+j][0]=min(dp[i+j][0],dp[i][1]+a[i+j]-a[i]); dp[i+j][1]=min(dp[i+j][1],dp[i][0]+b[i+j]-b[i]); } } cout<<min(dp[m][0],dp[m][1])<<endl; }}
ACdream - 1421
Charlie is going to take part in one famous TV Show. The show is a single player game. Initially the player has 100 dollars. The player is asked n questions, one after another. If the player answers the question correctly, the sum he has is doubled. If the answer is incorrect, the player gets nothing and leaves the show.
Before each question the player can choose to leave the show and take away the prize he already has. Also once in the game the player can buy insurance. Insurance costs c dollars which are subtracted from the sum the player has before the question. Insurance has the following effect: if the player answers the question correctly his prize is doubled as usually, if the player answers incorrectly the prize is not doubled, but the game continues. The player must have more than c dollars to buy insurance.
Charlie’s friend Jerry works on TV so he managed to steal the topics of the questions Charlie will be asked. Therefore for each question i Charlie knows p i — the probability that he will answer this question correctly. Now Charlie would like to develop the optimal strategy to maximize his expected prize. Help him.
Input
The first line of the input file contains two integer numbers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 10 9). The second line contains n integer numbers ranging from 0 to 100 — the probabilities that Charlie will answer questions correctly, in percent.
Output
Output one real number — the expected prize of Charlie if he follows the optimal strategy. Your answer must have relative or absolute error within 10 - 8
.
Sample Input
2 100
50 50
2 50
50 50
2 50
60 0
Sample Output
100
112.5
120
Hint
The optimal strategy in the second example is to take insurance for the second question. In this case the expected prize is 1/2 × 0 + 1/2 × (1/2 × 150 + 1/2 × 300).
In the third example it is better to leave the show after the first question, because there is no reason to try to answer the second one.
搜索dfs,递归的过程需要注意,还有过程中用double。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int n;double m;double a[210];double dfs(int s,double sum,int flag){ if(s>n) { return sum; } else { double ans=max(sum,a[s]*dfs(s+1,sum*2,flag)); double res=0; if(flag==0&&sum>m) { res+=a[s]*dfs(s+1,(sum-m)*2,1); res+=(1-a[s])*dfs(s+1,sum-m,1); } ans=max(res,ans); return ans; }}int main (){ while(~scanf("%d%lf",&n,&m)) { int i; for(i=1;i<=n;i++) { scanf("%lf",&a[i]); a[i]=a[i]/100; } double ans=dfs(1,100,0); printf("%f\n",ans); }}
- 2017.10.23
- 2017.10.23
- 2017.10.23
- [2017.10.23]作业04
- Test 2017.10.23
- 2017.10.23一试
- 2017.10.23工作日记
- 2017.10.23总结
- 2017.10.23 LeetCode
- 2017.10.23学习收藏
- 2017.10.23测试
- 2017.10.23 mmap()函数说明
- NOIP 2017.10.23 总结+心得
- 2017.10.23 硬币购物 失败总结
- 安卓开发日记---2017.10.23
- 2017.10.23 chess 中国象棋 思考记录
- NOIP2017赛前模拟(2017.10.23)
- 2017.10.23 卡牌游戏 失败总结
- 运维之shell篇------1. Shell概述 、 编写及执行脚本 、 Shell变量
- 短信接口防刷攻略
- vue.js的devtools安装
- FIFO、LRU、OPT这三种置换算法的缺页次数
- iOS_关键字nullable、nonnull、null_resettable、_Null_unspecified
- 2017.10.23
- java链接用户名密码mongodb
- java 私有属性加get/set方法跟直接把属性设置成public有区别吗?
- Implement queue with two stack 用两个堆实现队列
- java中new Class[]{Socket.class}写法的意思
- 学习设计模式的目标
- 封装ArrayList
- 阿里云媒体转码MTS使用教程
- Android Okhttp缓存:Cache,创建OkHttpClient实现(一)