题目链接: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(大坑)的更多相关文章

  1. hdu 4576(简单概率dp | 矩阵优化)

    艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那 ...

  2. Palindrome_滚动数组&&DP

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  3. poj - 1159 - Palindrome(滚动数组dp)

    题意:一个长为N的字符串( 3 <= N <= 5000).问最少插入多少个字符使其变成回文串. 题目链接:http://poj.org/problem?id=1159 -->> ...

  4. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  5. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  6. Making the Grade_滚动数组&&dp

    Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more tha ...

  7. Gym 100507G The Debut Album (滚动数组dp)

    The Debut Album 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/G Description Pop-group & ...

  8. 【滚动数组】 dp poj 1036

    题意:一群匪徒要进入一个酒店.酒店的门有k+1个状态,每个匪徒的参数是:进入时间,符合的状态,携带的钱. 酒店的门刚开始状态0,问最多这个酒店能得到的钱数. 思路: dp数组为DP[T][K]. 转移 ...

  9. hdu 4576 (简单dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...

随机推荐

  1. JAVA基础知识之网络编程——-网络通信模型(IO模型)

    <Unix网络编程:卷1>中介绍了5中I/O模型,JAVA作为运行在宿主机上的程序,底层也遵循这5中I/O模型规则.这5中I/O模型分别是: 阻塞式IO 非阻塞式IO I/O复用 信号驱动 ...

  2. noi 4982 踩方格

    题目链接:http://noi.openjudge.cn/ch0206/4982/ 深搜很好写. DP:O(n) d[i] 为走 I 不的方案数, l[i],r[i],u[i]为第一步走 左,右,上, ...

  3. noi 9265 取数游戏

    题目链接:http://noi.openjudge.cn/ch0206/9265/ 题意:从自然数1到N中不取相邻2数地取走任意个数,问方案数. 解法:f[i][1]表示在前i个数中选了第i个的方案数 ...

  4. python学习之字典

    1.字典 列表存储的数据比较单一也不够灵活,这时我们可以使用字典来存储某些多内容的数据,字典是无顺序的 1.简单的字典 book={ 'huqiang':13457412571, 'Jasper':1 ...

  5. 原创开源项目HierarchyViewer for iOS 2.1 Beta新功能介绍

    回顾 HierarchyViewer for iOS是我们发布的一个开源项目,采用GPL v3.0协议. HierarchyViewer for iOS可以帮助iOS应用的开发和测试人员,在没有源代码 ...

  6. 10-JS数组

    数组的定义和创建 数组是值得有序集合.JavaScript数组是无类型的. 数组对象的作用是:使用单独的变量名来存储一系列的值. 数组的创建 有两种向数组赋值的方法(你可以添加任意多的值,就像你可以定 ...

  7. 类似\u4e0b\u6ce8\u903e\u65f6解码

    HttpUtility.UrlDecode("\u4e0b\u6ce8\u903e\u65f6"); HttpUtility.UrlDecode("\\u5c1a\\u6 ...

  8. GPIO相关知识

    参考资料: 1. 维基百科GPIO 2. GPIO博客资料(一) 3. MMIO和PMIO 知识点: ● GPIO是General-purpose input/output的缩写,是一个在集成电路上的 ...

  9. C#浅拷贝与深拷贝区别

    也许会有人这样解释C# 中浅拷贝与深拷贝区别: 浅拷贝是对引用类型拷贝地址,对值类型直接进行拷贝. 不能说它完全错误,但至少还不够严谨.比如:string 类型咋说? 其实,我们可以通过实践来寻找答案 ...

  10. sqlite与android交互 (封装)

    学android已经有大概一周时间了吧 ,总感觉自己基础不怎么好,只能通过一点一点积累着敲来巩固平常的知识,有的时候就先不封装的敲一遍,再封装上,有些语句真的记不住,虽然知道他是什么意思,于是乎就反复 ...