mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-19 21:51:44 +00:00
Compare commits
4 Commits
f6d958f00a
...
a288f0c5ec
| Author | SHA1 | Date | |
|---|---|---|---|
| a288f0c5ec | |||
| 9f190cb94c | |||
| 3c29bca56e | |||
| 66740ddb77 |
57
src/11/13/P3102.cpp
Normal file
57
src/11/13/P3102.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
#define printf
|
||||
const ll p=2014;
|
||||
std::string s;
|
||||
ll n;
|
||||
std::vector<std::vector<ll>> dp;
|
||||
|
||||
static inline ll dfs(const ll l,const ll r){
|
||||
struct S{
|
||||
const ll &l,&r,&dp;
|
||||
S(const ll&l,const ll&r,const ll&dp):l(l),r(r),dp(dp){
|
||||
printf("dfs l=%lld, r=%lld, START\n",l,r);
|
||||
}
|
||||
~S(){
|
||||
printf("dfs l=%lld, r=%lld, ret=%lld\n",l,r,dp);
|
||||
}
|
||||
}raii(l,r,dp[l][r]);
|
||||
const ll nlen=r-l+1;
|
||||
if(l>r)return 0;
|
||||
if(dp[l][r])return dp[l][r];
|
||||
dp[l][r]=1;
|
||||
if(nlen<=2)return dp[l][r]=1;
|
||||
for(ll i=l+1;i<=r;i++){
|
||||
if(i-l==r-i+1)continue;
|
||||
const ll clen=std::min(i-l,r-i+1);
|
||||
if(i-l==1&&r-i+1==1)continue;
|
||||
for(ll j=0;j<clen;j++){
|
||||
if(s[l+j]!=s[i+j])goto nxt1;
|
||||
}
|
||||
dp[l][r]=((i-l>r-i+1?dfs(l, i-1):dfs(i, r))+dp[l][r])%p;
|
||||
nxt1:;
|
||||
for(ll j=0;j<clen;j++){
|
||||
if(s[i-1-j]!=s[r-j])goto nxt2;
|
||||
}
|
||||
dp[l][r]=((i-l>r-i+1?dfs(l, i-1):dfs(i, r))+dp[l][r])%p;
|
||||
nxt2:;
|
||||
}
|
||||
return dp[l][r];
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>s;
|
||||
n=s.size();
|
||||
s=' '+s;
|
||||
dp.resize(n+1,std::vector<ll>(n+1));
|
||||
std::cout<<(dfs(1,n)-1+p)%p<<"\n";
|
||||
}
|
||||
28
src/11/13/P8905.cpp
Normal file
28
src/11/13/P8905.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
|
||||
ll n,m;
|
||||
struct P{
|
||||
ll u,v;
|
||||
};
|
||||
std::vector<std::vector<P>> a;
|
||||
std::vector<ll> f;
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>n>>m;
|
||||
a.resize(n+1);
|
||||
f.resize(n+1);
|
||||
for(ll i=1;i<=m;i++){
|
||||
ll u,v;
|
||||
std::cin>>u>>v;
|
||||
f[u]++,f[v]++;
|
||||
a[u].emplace_back(v);
|
||||
a[v].emplace_back(u);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user