题目链接: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. 【转】malloc与free的底层实现

    本文转自:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201210975312473/ 如何查看进程发生缺页中断的次数? 用ps ...

  2. 读书笔记 1 of Statistics :Moments and Moment Generating Functions (c.f. Statistical Inference by George Casella and Roger L. Berger)

    Part 1: Moments Definition 1 For each integer $n$, the nth moment of $X$, $\mu_n^{'}$ is \[\mu_{n}^{ ...

  3. PHP 用户登录与退出

    PHP 用户登录与退出 登录页面 login.html 负责收集用户填写的登录信息. <fieldset> <legend>用户登录</legend> <fo ...

  4. [bzoj3555]企鹅QQ(hash)

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1645  Solved: 616[Submit][Statu ...

  5. [Mysql] mysql临时表corrupt

    问题描述 机房临时硬件问题, 机器掉电. 恢复后, 重启mysql进程, 结果出现core dump. 而且一直循环, 无法终止, 只能kill掉. backtrace如下. # service my ...

  6. SQL语言增加、修改、删除数据的语法

    增加 insert into 表名(字段1,字段2) values ('字段1的值','字段2的值'); 修改 update 表名 set 字段1='赋予字段1的新值',字段2='赋予字段2的新值' ...

  7. c语言->和 .

    ->和 . 都是用于访问结构数据的符号. struct point { int x; int y; }; . 符号是在表达式中引用某个特定结构中的成员: 结构名.成员 例如: struct po ...

  8. zabbix3.0.4 部署之一 (简介)

    官方网站:http://www.zabbix.com/ 下载地址:http://www.zabbix.com/download.php zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视 ...

  9. Laravel 5 数据库迁移文件示例

    php artisan make:migration create_stocks_table 在项目根目录执行上面的命令后,会在database/migrations目录下生成2016_06_03_1 ...

  10. python--分布式爬虫

    //server import socket, select, re, queue, redis from multiprocessing import Pool, cpu_count from py ...