G - Damaged Bicycle 状压+最短路,D-七圣召唤_概率dp

142 篇文章 1 订阅
92 篇文章 0 订阅

G - Damaged Bicycle 状压+最短路

最短路处理出1号节点和带车子的点到n的距离dist[x][n],G可以从节点1直接走到n,也可以从节点1走到带车子的节点再骑到n,如果车子坏了可以走到n,也可以走到下一个车子节点再进行之前的步骤,所以可以记忆化搜索一下,dp[sta][x],sta表示走了几个关键点,是一个压缩的二进制,x是当前的关键点,转移就是

dp[sta][x]=min(dp[sta][x],1.0*(1-p[x])*dist[x][n]/r+p[x]*(1.0*dist[x][a[i]]/t+dfs(sta|(1<<i-1),i)));

该点的车子没坏的期望加上坏了走到下一个关键点的期望

【超好懂的比赛题解】2021CCPC哈尔滨站 个人题解_RWLinno的博客-CSDN博客

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pause system("pause")
using namespace std;
const int N=1e6+5;
const int inf=1e18;
double t,r;
int n,m,head[N],cnt,k,a[22];
struct Edge
{
    int next,to;
    int w;
}e[N];
void addedge(int from,int to,int w)
{
    e[++cnt].next=head[from];
    e[cnt].to=to;
    e[cnt].w=w;
    head[from]=cnt;
}
int vis[N],dist[22][N];
double dp[N][22],p[22];
struct node
{
    int id,dis;
    bool operator<(const node &a)const
    {
        return a.dis<dis;
    }
};
void dij(int s,int num)
{
    for(int i=1;i<=n;i++) vis[i]=0,dist[num][i]=inf;
    dist[num][s]=0;
    priority_queue<node>q;
    q.push(node{s,0});
    while(!q.empty())
    {
        node u=q.top();q.pop();
        int now=u.id;
        double dis=u.dis;
        if(vis[now]) continue;
        vis[now]=1;
        for(int i=head[now];i;i=e[i].next)
        {
            int j=e[i].to;
            if(dist[num][now]+e[i].w<dist[num][j])
            {
                dist[num][j]=dist[num][now]+e[i].w;
                if(!vis[j]) q.push(node{j,dist[num][j]});
            }
        }
    }
}
double dfs(int sta,int x)
{
    if(dp[sta][x]) return dp[sta][x];
    double res=1.0*p[x]*dist[x][n]/t+(1.0-p[x])*dist[x][n]/r;
    for(int i=1;i<=k;i++)
    {
        if((sta>>i-1)&1) continue;
        res=min(res,1.0*(1-p[x])*dist[x][n]/r+p[x]*(1.0*dist[x][a[i]]/t+dfs(sta|(1<<i-1),i)));
    }
    return dp[sta][x]=res;
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>t>>r>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;double w;
        cin>>u>>v>>w;
        addedge(u,v,w);
        addedge(v,u,w);
    }
    cin>>k;
    a[0]=1;p[0]=1;
    for(int i=1;i<=k;i++)
    {
        cin>>a[i]>>p[i];
        p[i]/=100.0;
    }
    for(int i=0;i<=k;i++) dij(a[i],i);
    double ans=dfs(0,0);
    if(dist[0][n]>=inf) cout<<"-1\n";
    else cout<<fixed<<setprecision(10)<<ans<<endl;
    pause;
    return 0;
}

D-七圣召唤_概率dp

第一个设dp[i]为抽到i种卡片需要的期望次数,显然dp[1]=1,然后

dp[i]=\frac{i-1}{k}dp[i]+\frac{k-i+1}{k}dp[i-1]+1

意思就是有\frac{i-1}{k}的概率是抽到已经抽到的牌,那么需要求的期望还是不变的,还是需要dp[i]来转移,有\frac{k-i-1}{k}的概率是抽到没抽到的牌,那么就可以由dp[i-1]来转移

第二个答案f[i],可以理解成f[i]=(k-f[i-1])/k+f[i-1],在i-1次的基础上加上这一次成功的概率,应该说是期望,理解是价值为1,所以就直接加上了

2022 年辽宁省大学生程序设计竞赛 个人题解_RWLinno的博客-CSDN博客_辽宁省程序设计大赛

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pause system("pause")
using namespace std;
const int N=1e6+5;
const int inf=1e18;
int n,k;
double qpow(double a,int b)
{
    double res=1.0;
    while(b)
    {
        if(b&1) res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}
double dp[N],f[N];
signed main()
{
    //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    dp[0]=0;dp[1]=1;
    for(int i=2;i<=k;i++)
    {
        dp[i]=(1.0*(k-i+1)*dp[i-1]/k+1.0)*k/(k-i+1);
        //cout<<dp[i]<<" "<<i<<endl;
    }
    f[0]=0;f[1]=1;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+1.0*(k-f[i-1])/k;
    cout<<fixed<<setprecision(10)<<dp[k]<<" "<<f[n]<<endl;
    pause;
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
This error message indicates that the linker (ArmLink) failed to execute during the build process for a project on an STM32 microcontroller using Keil software. There are several potential causes for this error, including: 1. Missing or corrupted ArmLink executable file: Check that the ArmLink executable file is present in the specified path (D:\keil 5\ARM\ARMCC\Bin\ArmLink) and that it is not corrupted or damaged. 2. Insufficient disk space: Ensure that there is sufficient disk space available on the drive where Keil software is installed and where the project files are located. 3. Incompatible or outdated software components: Verify that all software components used in the project (such as the STM32 device driver, CMSIS library, and Keil software) are compatible with each other and up-to-date. 4. Incorrect project settings: Check that the project settings (such as the linker script, memory map, and build options) are correctly configured for the STM32 microcontroller and the specific application. 5. Hardware issues: There may be an issue with the STM32 microcontroller or the hardware interface used to connect it to the computer. Check that the hardware components are functioning properly and that the microcontroller is properly connected. To resolve this error, try the following steps: 1. Reinstall the Keil software and verify that all necessary components are installed correctly. 2. Check for and remove any corrupted or damaged files related to the ArmLink executable. 3. Verify that there is sufficient disk space available on the system drive. 4. Ensure that all software components used in the project are compatible and up-to-date. 5. Verify that the project settings are correctly configured for the STM32 microcontroller and application. 6. Check for and resolve any hardware issues that may be causing the error.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

killer_queen4804

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值