#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); #define mm(a,b) memset(a,b,sizeof(a)) #define fr(i,a,b) for(int i=a;i<=b;i++) using namespace std; int read(){int x=0,f=1;char c=getchar(); for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);return x*f;} struct path{int to,v;}; struct node{int num,v;bool operator <(const node &b) const{return v>b.v;}}; vector<path> g[10001]; priority_queue<node> q; int m,n,k,ans,dist[10001][21]; bool vis[10001][21]; int min(int a,int b){return a<b?a:b;} void dij(){node now;mm(dist,INF),mm(vis,0); dist[1][0]=0;q.push((node){1,0}); while(!q.empty()){now=q.top();q.pop(); int t1=now.num%(n+1),t2=now.num/(n+1); vis[t1][t2]=true; fr(i,0,int(g[t1].size())-1){path t=g[t1][i]; if((!vis[t.to][t2])&&dist[t.to][t2]>dist[t1][t2]+t.v){ dist[t.to][t2]=dist[t1][t2]+t.v; q.push((node){t2*(n+1)+t.to,dist[t.to][t2]});} if((!vis[t.to][t2+1])&&t2<k&&dist[t.to][t2+1]>dist[t1][t2]){ dist[t.to][t2+1]=dist[t1][t2]; q.push((node){(t2+1)*(n+1)+t.to,dist[t.to][t2+1]});} }}} int main(){init("school");n=read(),m=read(),k=read(); fr(i,1,m){int a=read(),b=read(),v=read(); g[a].push_back((path){b,v});g[b].push_back((path){a,v});} dij();ans=INF;fr(i,0,k)ans=min(ans,dist[n][i]); printf("%d",ans);return 0; }
#include <cstdio> #include <cstring> int n,mid,dp[2501][5]; #define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); #define fr(i,a,b) for(int i=a;i<=b;i++) using namespace std; int read(){int x=0,f=1;char c=getchar(); for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);return x*f;} int min(int a,int b){return a<b?a:b;} int main(){init("quad"); n=read();mid=(n-1)>>1;dp[0][0]=1; fr(i,1,n)fr(j,1,4)fr(k,1,min(mid,i))dp[i][j]+=dp[i-k][j-1]; printf("%d",dp[n][4]);return 0; }
#include <cstdio> #include <cstring> #define INF 0x3f3f3f3f int n,m,t1,t2; int a[301],b[301]; int dp[501][301]; #define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); #define mm(a,b) memset(a,b,sizeof(a)) #define fr(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; int read(){int x=0,f=1;char c=getchar(); for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);return x*f;} int max(int a,int b){return a>b?a:b;} int main(){init("solve"); n=read(),m=read(); fr(i,1,m)a[i]=read(),b[i]=read(); mm(dp,INF);dp[2][0]=n;int i=2; while(dp[i][m]==INF){ fd(j,m,0) if(dp[i][j]!=INF){int k=j+1; t1=dp[i][j],t2=dp[i+1][j]=n; while(t1>=a[k]&&t2>=b[k])t1-=a[k],t2-=b[k], dp[i][k]=dp[i][k]==INF?t1:max(dp[i][k],t1), dp[i+1][k]=dp[i+1][k]==INF?t2:max(dp[i+1][k],t2),k++; }i++;}printf("%d",i);return 0;}
#include<cstdio> #define inf 1e9 #define N 100005 #define S1 dis[x]+e[i].v #define S2 sdis[x]+e[i].v using namespace std; //-------------------------- template<class T>inline void cin(T&x){ static char c;static int y; for(c=getchar(),x=0,y=1;c<48||57<c;c=getchar())if(c=='-')y=-1; for(;48<=c&&c<=57;c=getchar())x=((x+(x<<2))<<1)+(c^'0'); x*=y;} void outint(int x){if(x>=10) outint(x/10);putchar(x%10+'0');} //--------------------------optimization above struct node{int to,next,v;}e[N<<1];//e:edge int head[N],cnt;//cnt:counter,head:point void insert(int x, int y, int v){e[++cnt].to=y;e[cnt].next=head[x];e[cnt].v=v;head[x]=cnt;} int n,m,dis[N],sdis[N],q[N<<2]; bool inq[N]; void SPFA(){for(int i=1;i<=n;i++)dis[i]=sdis[i]=inf; dis[1]=0; q[0]=1; int l=0,r=1,t; inq[1]=1;//initialization,set the first dis as 0,and push it into the queue,and make it enter_mark true while (l<r){int x=q[l++];//if the queue is empty,just set x as the queue_head ,and then renew the queue_head for (int i=head[x];i;i=e[i].next){t=e[i].to;//from the first point ,keep going next if (dis[t]>S1){sdis[t]=dis[t];dis[t]=S1;if (!inq[t])inq[t]=1,q[r++]=t;} //old solution can make better case //make second_solution as the old solution,renew the old solution,++++if it has not enter queue,enter it and then mark it true if (dis[t]<S1&&sdis[t]>S1){sdis[t]=S1;if (!inq[t])inq[t]=1,q[r++]=t;} //second_solution can make better case //change it and then just as++++ if (sdis[t]>S2){sdis[t]=S2;if (!inq[t])inq[t]=1,q[r++]=t;} //if can make second_solution_map's better case //change it and then just as++++ }inq[x]=0;//make it false } } int main(){cin(n),cin(m);int x,y,v; for (int i=1; i<=m; i++){cin(x),cin(y),cin(v);insert(x,y,v);insert(y,x,v);}//make edge SPFA();outint(sdis[n]);return 0; }//quick and easy,so this is the best solution //noted by franzl lang