惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
U
Unit 42
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
小众软件
小众软件
V
Visual Studio Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
GbyAI
GbyAI
爱范儿
爱范儿
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
博客园_首页
D
Docker
A
About on SuperTechFans
G
Google Developers Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - Franky

hsfzxjy 的博客

解决 VSCode + CMake + MSVC 编译器信息乱码的问题 使用 3090 部署 1.58bit 动态量化版 DeepSeek R1 671b 如何在 VS Code DevContainer 中配置 HTTP 代理 如何在跳板机背后的服务器上使用 VS Code Remote - Containers Cohesive Digests for Ints and Floats Rust 中的隐匿概念 —— Place(位置) 美术馆 一尺之槌,日取其半,1075日而竭 老生常谈:使用 Cloudflare 自选 IP 加速站点访问 辩义 State、Nation 与 Country 将 Base64 编码的数据快速转换为 Uint8Array 折腾 NPU·第1章 —— 搭建 Level Zero 开发环境 折腾 NPU·第0章 —— Intel NPU 概述与 Level-Zero 新增域名 monad.run CSS 中为特定字符设置不同字体 Arbitary Lifetime Transmutation via Rust Unsoundness Dijkstra 算法的延伸 Manacher 回文计数算法 硬卧 Go Fact: Zero-sized Field at the Rear of a Struct Has Non-zero Size Display *big.Rat Losslessly and Smartly in Golang 代码的仪式 Building Electron From Scratch 中式亲属称谓研究之一:构建半群 Some Notes on Kotlin Coroutines Git sparse-checkout and partial clones for Mega-Repos 辩义“封建” Diving from the CUDA Error 804 into a bug of libnvidia-container Modern Cryptography, GPG and Integration with Git(hub) Move the Root Partition of Ubuntu
NOIP2011 表达式计算
2014-09-22 · via hsfzxjy 的博客

记得 11 年的时候,觉得这道题爆难,根本无从下手。三年后再次回顾,终于 AC 了,就当是对表达式求值和动态规划的复习吧。

题目:Link


#include <iostream>
#define Mod 10007
using namespace std;

typedef struct {
long long v0;
long long v1;
char ch;
} vertex;

vertex f[100000];

void merge_sum(int p) {
int w0 = f[p-1].v0 * f[p].v0;
int w1 = f[p-1].v0*f[p].v1+f[p-1].v1*f[p].v0+f[p-1].v1*f[p].v1;
f[p-1].v0 = w0 % Mod;
f[p-1].v1 = w1 % Mod;
}

inline void merge_product(int p)
{
int w0=f[p-1].v0*f[p].v0+f[p-1].v0*f[p].v1+f[p-1].v1*f[p].v0;
int w1=f[p-1].v1*f[p].v1;
f[p-1].v0=w0%Mod;
f[p-1].v1=w1%Mod;
}

int main()
{
int n;
cin>>n;
f[0].v0=f[0].v1=1;
while (n--)
{
now++;
cin>>f[now].ch;
f[now].v0=f[now].v1=1;
if (f[now].ch=='+')
{
if (f[now-1].ch=='*')
{
now--;
merge_product(now);
f[now]=f[now+1];
}
if (f[now-1].ch=='+')
{
now--;
merge_sum(now);
f[now]=f[now+1];
}
}
if (f[now].ch=='*')
if (f[now-1].ch=='*')
{
now--;
merge_product(now);
f[now]=f[now+1];
}
if (f[now].ch==')')
{
now--;
if (f[now].ch=='*')
{
merge_product(now);
now--;
}
if (f[now].ch=='+')
{
merge_sum(now);
now--;
}
now--;
f[now].v0=f[now+1].v0;
f[now].v1=f[now+1].v1;
if (f[now].ch=='*')
{
merge_product(now);
now--;
}
}
}
if (f[now].ch=='*')
{
merge_product(now);
now--;
}
if (f[now].ch=='+')
{
merge_sum(now);
now--;
}
cout<<f[0].v0;
return 0;
}

作者:hsfzxjy
链接:
许可:CC BY-NC-ND 4.0.
著作权归作者所有。本文不允许被用作商业用途,非商业转载请注明出处。