HDU 4576 简单概率 + 滚动数组DP(大坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576
坑大发了,居然加 % 也会超时;
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%I64d", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%I64d\n", n)
#define MAXN 1000005
int n, l, m, r, d;
int t = , mm;
double dp[][];
int main()
{
while(~scanf("%d%d%d%d", &n, &m, &l, &r) && (n + m + l + r))
{
t = ;
repu(i, , n + ) dp[][i] = 0.0;
dp[][] = 1.0;
int c;
repu(i, , m)
{
sfi(d);
if(l == && r == n) continue;
c = d / n;
mm = d - n * c;
if(mm)
{
t = !t;
repu(j, , n + )
{
int lt, rt;
if((n + (j - mm)) >= n) lt = (n + (j - mm)) - n;
else lt = (n + (j - mm));
if((j + mm) >= n) rt = (j + mm) - n;
else rt = (j + mm);
if(lt == ) lt = n;
if(rt == ) rt = n;
dp[t][j] = (dp[!t][lt] + dp[!t][rt]) / 2.0;
//cout<<j<<" :"<<dp[t][j]<<endl;
}
}
}
double ans = 0.0;
if(l == && r == n) ans = 1.0;
else
repu(i, l, r + ) ans += dp[t][i];
printf("%.4lf\n", ans);
}
return ;
}
AC
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%I64d", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%I64d\n", n)
#define MAXN 1000005
int n, l, m, r, d;
int t = , mm;
double dp[][];
int main()
{
while(~scanf("%d%d%d%d", &n, &m, &l, &r) && (n + m + l + r))
{
t = ;
repu(i, , n + ) dp[][i] = 0.0;
dp[][] = 1.0;
int c;
repu(i, , m)
{
sfi(d);
if(l == && r == n) continue;
c = d / n;
mm = d - n * c;
if(mm)
{
t = !t;
repu(j, , n + )
{
int lt, rt;
lt = (n + (j - mm)) % n;
rt = (j + mm) % n;
// if((n + (j - mm)) >= n) lt = (n + (j - mm)) - n;
// else lt = (n + (j - mm));
// if((j + mm) >= n) rt = (j + mm) - n;
// else rt = (j + mm);
if(lt == ) lt = n;
if(rt == ) rt = n;
dp[t][j] = (dp[!t][lt] + dp[!t][rt]) / 2.0;
//cout<<j<<" :"<<dp[t][j]<<endl;
}
}
}
double ans = 0.0;
if(l == && r == n) ans = 1.0;
else
repu(i, l, r + ) ans += dp[t][i];
printf("%.4lf\n", ans);
}
return ;
}
TLE
% 慎用啊必须,虽然不知道为什么
HDU 4576 简单概率 + 滚动数组DP(大坑)的更多相关文章
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- Palindrome_滚动数组&&DP
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- poj - 1159 - Palindrome(滚动数组dp)
题意:一个长为N的字符串( 3 <= N <= 5000).问最少插入多少个字符使其变成回文串. 题目链接:http://poj.org/problem?id=1159 -->> ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- Making the Grade_滚动数组&&dp
Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...
- Gym 100507G The Debut Album (滚动数组dp)
The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...
- 【滚动数组】 dp poj 1036
题意:一群匪徒要进入一个酒店.酒店的门有k+1个状态,每个匪徒的参数是:进入时间,符合的状态,携带的钱. 酒店的门刚开始状态0,问最多这个酒店能得到的钱数. 思路: dp数组为DP[T][K]. 转移 ...
- hdu 4576 (简单dp+滚动数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...
随机推荐
- noi 4982 踩方格
题目链接:http://noi.openjudge.cn/ch0206/4982/ 深搜很好写. DP:O(n) d[i] 为走 I 不的方案数, l[i],r[i],u[i]为第一步走 左,右,上, ...
- [问题2015S06] 复旦高等代数 II(14级)每周一题(第七教学周)
[问题2015S06] 设 \(V\) 是数域 \(\mathbb{K}\) 上的 \(n\) 维线性空间, \(\varphi\) 是 \(V\) 上的线性变换. (1) 求证: 对任一非零向量 ...
- Zabbix 3.0.3 SQL Injection
Zabbix version 3.0.3 suffers from a remote SQL injection vulnerability. ============================ ...
- VirtualProvider (VirtualCube)虚拟立方体
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 从零开始HTML(一 2016/9/19)
就是准备跟着W3C上的教程过一遍HTML啦,边看边记录更便于理解记忆吧~ 1.属性 HTML 标签可以拥有属性.属性提供了有关 HTML 元素的更多的信息.属性总是以名称/值对的形式出现,比如:nam ...
- [Prodinner项目]学习分享_第二部分_Entity到DB表的映射
1.单纯映射 基本语法为 modelBuilder.Entity<InsType>().ToTable("TB_InsType"); 2.一对多映射(表关系) 实体类B ...
- openstack Icehouse发布
OpenStack 2014.1 (Icehouse) Release Notes General Upgrade Notes Windows packagers should use pbr 0.8 ...
- zabbix3.0.4 部署之二 (Centos6.5系统准备)
1.安装Centos6.5 2.6.32-642.4.2.el6.x86_64 升级所有软件至最新: yum update 2.同步时间.安装ntpd yum install ntpddate n ...
- MYSQL常见错误及其解决方式
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 亚马逊云服务器AWS安装CentOS
亚马逊云服务器默认创建的实例,在停止之后再启动的情况下,IP会发生改变.所以我们最好先创建一个弹性IP,即EIP,不过我也不清楚这个费用. 1.按如图操作创建一个弹性IP,弹性IP创建之后可以随便绑定 ...