题目链接: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. python基本数据类型之集合set

    一.集合的定义 set集合,是一个无序且不重复的元素集合. 集合对象是一组无序排列的可哈希的值,集合成员可以做字典中的键.集合支持用in和not in操作符检查成员,由len()内建函数得到集合的基数 ...

  2. POJ3420Quad Tiling(矩阵快速幂)

    Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3740 Accepted: 1684 Descripti ...

  3. [Machine-Learning] 机器学习中的几个度量指标

    Several classification metrics for ML/DM methods. 主要解释下机器学习(或数据挖掘)中的几个度量指标. 1. 关于 "TN/TP/FN/FP&q ...

  4. Eclipse开发过程中个VM Arguments的设置

    Eclipse开发过程中个VM Arguments的设置 1:jre中的Default VM Arguments: -Xms256M -Xmx640M -XX:PermSize=256m -XX:Ma ...

  5. [问题2014A01] 解答三(升阶法,由董麒麟同学提供)

    [问题2014A01] 解答三(升阶法,由董麒麟同学提供) 引入变量 \(y\),将 \(|A|\) 升阶,考虑如下行列式: \[|B|=\begin{vmatrix} 1 & x_1-a & ...

  6. Dialog , ProgressDialog , PopWindow 区别

    本质区别: Dialog:非阻塞对话框,弹出对话框时时,后台还可以做事情,点击背景时,对话框消失 ProgressDialog:带有圆形进度或者条形进度的对话框,一般结合handler使用.任务完成后 ...

  7. JDBC连接执行MySQL存储过程报权限错误

    今天在测试项目的时候  突然就报了一个错出来. User does not have access to metadata required to determine stored procedure ...

  8. Matlab 霍夫变换 ( Hough Transform) 直线检测

    PS:好久没更新,因为期末到了,拼命复习中.复习久了觉得枯燥,玩玩儿霍夫变换直线检测 霍夫变换的基本原理不难,即便是初中生也很容易理解(至少在直线检测上是这样子的). 霍夫变换直线检测的基本原理:(不 ...

  9. DAS、SAN、NAS的区别

    在服务企业的过程中,经常会接触到存储,但是又容易和市面上的一些什么NAS等混淆. DAS 与主机直连的存储设备 NAS 存储设备自带文件系统 SAN 存储设备的互联依赖网络,比如IP-SAN, FC- ...

  10. css样式设计

    1.行内元素(图片.文本)水平居中 通过给父元素设置 text-align:center html代码: <body> <div class="txtCenter" ...