当前位置:网站首页>Path count 2 (DP + number of combinations)
Path count 2 (DP + number of combinations)
2022-06-11 03:29:00 【to cling】
daimayuan A daily topic div1 202
Solution
- dp[i] Go to the first place i Number of legal solutions for obstacles
- Come to the point (x, y) The number of all the schemes : C ( x + y − 2 , x − 1 ) C(x + y - 2, x - 1) C(x+y−2,x−1)
- d p [ i ] = C ( i . x + i . y − 2 , i . x − 1 ) − ∑ d p [ j ] ∗ C ( i . x − j . x + i . y − j . y , i . x − j . x ) dp[i] = C(i.x + i.y - 2, i.x - 1) - \sum dp[j] * C(i.x - j.x + i.y - j.y, i.x - j.x) dp[i]=C(i.x+i.y−2,i.x−1)−∑dp[j]∗C(i.x−j.x+i.y−j.y,i.x−j.x)
namely : Number of legal schemes = Number of all schemes - Number of all illegal schemes
Code
const ll mod = 1000000007;
using namespace std;
const int N = 2e6 + 5;
ll f[N];
ll inv[N], fac[N];
void init()
{
fac[0] = inv[1] = inv[0] = 1;
// Be careful :inv[0] = 1, That is, the inverse of the factorial of zero is 1
for (int i = 1; i <= 2e6; i++)
fac[i] = fac[i - 1] * i % mod;
// Find out first 1~n Inverse element
for (int i = 2; i <= 2e6; i++)
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
//1~n The inverse element accumulation of is 1~n The inverse element of the factorial of
for (int i = 2; i <= 2e6; i++)
inv[i] = inv[i] * inv[i - 1] % mod;
}
ll C(int n, int m)
{
return fac[n] * inv[n - m] % mod * inv[m] % mod;
}
pii s[N];
int main()
{
IOS;
init();
int n, m; cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> s[i].ft >> s[i].sd;
s[m + 1] = {
n, n };
for (int i = 1; i <= m + 1; i++)
{
f[i] = C(s[i].ft + s[i].sd - 2, s[i].ft - 1);
for (int j = 1; j < i; j++)
{
ll t = C(s[i].ft - s[j].ft + s[i].sd - s[j].sd, s[i].ft - s[j].ft);
f[i] = ((f[i] - f[j] * t % mod) % mod + mod) % mod;
}
}
cout << f[m + 1] << endl;
return 0;
}
边栏推荐
猜你喜欢

【ELT.ZIP】OpenHarmony啃论文俱乐部——多层存储分级数据压缩

Azure Kubernates Service 更新|提升开发体验和效率

J. Balanced Tree

Canvas+svg line particle animation web page background

ThoughtWorks.QRCode功能齐全的生成器

has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header is present on the requested

ArTalk | 如何用最小投入,构建国产超融合进化底座?

The tide play power is really firepower! The first big screen cinema for young people? Cool open TV Max 86 "sudden attack

If no separation ----- > > login module nanny level source code analysis (0)

SQL查询连续三天登录的用户
随机推荐
Log4j use
Troubleshooting of single chip microcomputer communication data delay
If the source code of the home page module is not separated ----- > nanny level source code analysis (1)
SQL | some indicators of the game industry
Gd32 can sends no mailbox fault
net::ERR_ FILE_ NOT_ Found error
蓄力618 ,苏宁如何打下这场硬仗?
Reasons why Chinese comments cannot be written in XML
Azure Kubernates Service 更新|提升开发体验和效率
Oppo K9 tests "bundling sales" and consumers "earn" or "lose"?
【安全科普】今天你被社工了吗?
J. Balanced Tree
Canvas drawing -- how to place the drawing in the center of the canvas
R bioinformatics statistical analysis
JSCPCP L. Collecting Diamonds(思维)
GD32F4串口dma接收问题解决
postgresql copy语句
Right click PowerShell here function add
rt-thread测试
js最常用的排序---手撕js系列