19 条题解

  • 0
    @ 2026-1-6 16:31:30
    #include<bits/stdc++.h>
    using namespace std;
    int n,a[10000],f[10000],maxx;
    int main()
    {
       cin>>n;
       for(int i=1;i<=n;i++) cin>>a[i];
       for(int i=1;i<=n;i++)
       {
          int maxn=0;
          for(int j=1;j<=i-1;j++) if(a[i]>a[j]) maxn=max(f[j],maxn);
          f[i]=maxn+1;
          maxx=max(maxx,f[i]);
       }
       cout<<maxx;
       return 0;
    }
    
    • 0
      @ 2026-1-5 16:34:32
      
      

      #include<bits/stdc++.h> using namespace std; long long n,m,f[278][19178],a[178]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=0;i<=n;i++) f[i][0]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(a[i]>j) f[i][j]=f[i-1][j]; else f[i][j]=f[i-1][j]+f[i-1][j-a[i]]; } cout<<f[n][m]; return 0; }

      
      
      • 0
        @ 2025-12-29 16:52:45
        #include<bits/stdc++.h>
        using namespace std;
        int fx[5]={0,-1,1,0,0},fy[5]={0,0,0,-1,1},n,m,ans=INT_MAX,x,y,p,f[1100][200];
        char a[1100][200];
        void sy(int x,int y,int s)
        {
        	if (a[x][y]=='*')
        	{
        		p=1;
        		ans=min(ans,s);
        		return;
        	}
        	for (int i=1;i<=4;i++)
            {
                int tx=x+fx[i],ty=y+fy[i];
        		    if (tx<=n&&tx>=1&&ty>=1&&ty<=m&&a[tx][ty]!='#')
        			   if (s+1<f[tx][ty])
        			   {
        				   f[tx][ty]=s+1;
        				   sy(tx,ty,s+1);
        		       }
            }
        }
        int main() 
        {
        	cin>>n>>m;
        	for (int i=1;i<=n;i++)
        		for (int j=1;j<=m;j++)
        		{
        			cin>>a[i][j];
        			if (a[i][j]=='@') x=i,y=j;
        			f[i][j]=INT_MAX;
        		}
        	sy(x,y,0);
        	if (p==1) cout<<ans;
        	  else cout<<"-1";
        }
        
        • 0
          @ 2025-12-29 16:52:17
          #include<bits/stdc++.h>
          using namespace std;
          int fx[5]={0,-1,1,0,0},fy[5]={0,0,0,-1,1},h,w,s,maxs=INT_MIN;
          char a[120][120];
          bool f[120][120];
          void sy(int x,int y)
          {
          	for (int i=1;i<=4;i++)
          		if (x+fx[i]>=1&&y+fy[i]>=1&&x+fx[i]<=w&&y+fy[i]<=h&&a[x+fx[i]][y+fy[i]]=='.'&&f[x+fx[i]][y+fy[i]]==0)
          		{
          			f[x+fx[i]][y+fy[i]]=1;
          			s++;
          			sy(x+fx[i],y+fy[i]);
          	    }
          } 
          int main() 
          {
          	cin>>h>>w;
          	for (int i=1;i<=w;i++)
          		for (int j=1;j<=h;j++) cin>>a[i][j];
          	for (int i=1;i<=w;i++)
          		for (int j=1;j<=h;j++) if (a[i][j]=='@') sy(i,j);
          	cout<<s+1; 
          }
          
          • 0
            @ 2025-12-29 16:41:32
            #include <bits/stdc++.h>
            using namespace std;
            long long n,x,s,ans,m,b[10000];
            int main()
            {
            	cin>>n>>m;
            	for(int i=1;i<=m;i++) cin>>x,b[x]=1;
            	for(int i=1;i<=n;i+=2)
                {
            		if(b[i]==0&&b[i+1]==0) s++;
            		else if(b[i]==0||b[i+1]==0) ans++;
            	}
            	cout<<s<<endl<<ans;
            	return 0;
            }
            
            • 0
              @ 2025-12-29 16:40:50
              #include <bits/stdc++.h>
              using namespace std;
              string s;
              int n;
              int main()
              {
              	cin>>n;
              	while(n)
                  {
              		s=char('A'+(n-1)%26)+s;
              		n=(n-1)/26;
              	}
              	cout<<s;
              	return 0;
              }
              
              • 0
                @ 2025-12-29 15:22:19
                #include<bits/stdc++.h>
                using namespace std;
                long long s[20][2],ans=0,n;
                bool p[20]={false};
                void dfs(int k)
                {
                    if(k>n)
                    {
                        ans++;
                        return ;
                    }
                    int a=s[k][0];
                    int b=s[k][1];
                    if(!p[a])
                    {
                        p[a]=true;
                        dfs(k+1);
                        p[a]=false;
                    }
                    if(!p[b])
                    {
                        p[b]=true;
                        dfs(k+1);
                        p[b]=false;
                    }
                }
                int main()
                {
                    cin>>n;
                    for(int i=1;i<=n;i++) cin>>s[i][0]>>s[i][1];
                    dfs(1);
                    cout<<ans;
                    return 0;
                }
                
                • 0
                  @ 2025-12-29 15:19:28
                  #include<bits/stdc++.h>
                  using namespace std;
                  long long n,k,a[100],i,s,t;
                  int main()
                  {
                      cin>>n>>k;
                      t=n;
                      i=2;
                      while(n!=1&&s<k-1)
                      {
                          if(n%i==0) n/=i,s++,a[s]=i;
                          else i++;
                      }
                      if(n>1)
                      {
                          cout<<t<<'=';
                          for(int i=1;i<=k-1;i++) cout<<a[i]<<'*';
                          cout<<n;
                      }
                      else cout<<"No answer!";
                  }
                  
                  • 0
                    @ 2025-12-25 17:04:52
                    #include <bits/stdc++.h>
                    using namespace std;
                    int n,m,k,x,y,s,a[105][105];
                    int main()
                    {
                    	cin>>n>>m>>k;
                        for(int i=1;i<=m;i++)
                        {
                            cin>>x>>y;
                            for(int j=max(y-2,1);j<=y+2;j++) a[x][j]=1;
                            for(int z=max(x-2,1);z<=x+2;z++) a[z][y]=1;
                            a[x-1][y-1]=1,a[x-1][y+1]=1,a[x+1][y+1]=1,a[x+1][y-1]=1;
                        }
                        for(int i=1;i<=k;i++)
                        {
                            cin>>x>>y;
                            for(int j=max(x-2,1);j<=x+2;j++)
                               for(int z=max(y-2,1);z<=y+2;z++) a[j][z]=1;;
                        }
                        for(int i=1;i<=n;i++)
                           for(int j=1;j<=n;j++) if(a[i][j]==0) s++;
                        cout<<s;
                    	return 0;
                    }
                    
                    • 0
                      @ 2025-12-25 15:36:14
                      #include<bits/stdc++.h>
                      using namespace std;
                      long long n,a[200],x,ans=0,sum=0,s;
                      bool f(int num,int x)
                      {
                          if(num==0&&x==0) return true;
                          while(num>0){
                              s=num%10;
                              if(s==x) return true;
                              num=num/10;
                          }
                          return false;
                      }
                      int main()
                      {
                          cin>>n;
                          for(int i=1;i<=n;i++) cin>>a[i];
                          cin>>x;
                          for(int i=1;i<=n;i++)
                          {
                              if(f(a[i],x))
                              {
                                  ans++;
                                  sum+=a[i];
                              }
                          }
                          cout<<ans<<" "<<sum;
                      }
                      
                      • 0
                        @ 2025-12-22 16:10:39
                        #include <bits/stdc++.h>
                        using namespace std;
                        int main()
                        {
                            cout<<0<<' '<<20<<endl;
                            for(int i=1;i<=19;i++)
                                if((100-i*6)%5==0) cout<<i<<' '<<(100-i*6)/5<<endl;
                            return 0;
                        }
                        
                        • 0
                          @ 2025-12-18 16:03:50
                          y+=n%10;
                                      n=n/10;
                          
                          • 0
                            @ 2025-12-18 15:12:33
                            #include <bits/stdc++.h>
                            using namespace std;
                            int n,k;
                            char f[1000];
                            void sy(int x,int y, int t)
                            {
                                if(y==n+1)
                                {
                                    if(t+x==0)
                                    {
                                        cout<<"1";
                                        for(int i=2;i<=n;i++)
                                           cout<<f[i]<<i;
                                           cout<<endl;
                                    }
                                    return ;
                                }
                                f[y]=' ';
                                if(x>0) sy(x*10+y,y+1,t);
                                   else sy(x*10-y,y+1,t);
                                f[y]='+';
                                sy(y,y+1,t+x);
                                f[y]='-';
                                sy(-y,y+1,t+x);
                            }
                            int main()
                            {
                                cin>>n;
                                sy(1,2,0);
                                return 0;
                            }
                            
                            • 0
                              @ 2025-12-16 16:13:28
                              #include <bits/stdc++.h>
                              using namespace std;
                              int fx[5]={0,-1,1,0,0},fy[5]={0,0,0,-1,1},n,m,ans=INT_MAX,f[100][100],x,y;
                              bool p;
                              char a[100][100];
                              void sy(int x,int y,int t)
                              {
                                  if(a[x][y]=='a')
                                  {
                                      p=1;
                                      if(t<ans) ans=t;
                                      return ;
                                  }
                                  for(int i=1;i<=4;i++)
                                  {
                                      int tx=x+fx[i];
                                      int ty=y+fy[i];
                                      if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&a[tx][ty]!='#')
                                      {
                                          if(a[tx][ty]=='x'&&t+2<=f[tx][ty])
                              			{
                                          	f[tx][ty]=t+2;
                                          	sy(tx,ty,t+2);
                              			} 
                                          else if(t+1<f[tx][ty])
                              			{
                                          	f[tx][ty]=t+1;
                                          	sy(tx,ty,t+1);
                              			}
                                      }
                                  }
                              }
                              int main()
                              {
                                  cin>>n>>m;
                                  for(int i=1;i<=n;i++)
                                      for(int j=1;j<=m;j++) cin>>a[i][j];
                                  for(int i=1;i<=n;i++)
                                      for(int j=1;j<=m;j++)
                              		{
                                      	if(a[i][j]=='r') x=i,y=j;
                                      	f[i][j]=INT_MAX;
                              		}
                                  sy(x,y,0);
                                  if(p==1) cout<<ans;
                                  else cout<<"Impossible";
                                  return 0;
                              }
                              
                              • 0
                                @ 2025-12-9 17:02:55
                                
                                

                                #include <bits/stdc++.h> using namespace std; int fx[5]={0,-1,1,0,0},fy[5]={0,0,0,-1,1},n,m,tx,ty,s,ans,maxx,minx,maxy,miny; bool f[1100][1100]; char a[1100][1100]; void sy(int x,int y) { for(int i=1;i<=4;i++) { tx=x+fx[i]; ty=y+fy[i]; if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&f[tx][ty]0&&a[tx][ty]'#') { s++; f[tx][ty]=1; maxx=max(maxx,tx); minx=min(minx,tx); maxy=max(maxy,ty); miny=min(miny,ty); sy(tx,ty); } } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]=='#'&&f[i][j]==0) { s=1; f[i][j]=1; minx=maxx=i; miny=maxy=j; sy(i,j); if((maxx-minx+1)*(maxy-miny+1)==s) ans++; else { cout<<"Bad placement."; return 0; } } cout<<"There are "<<ans<<" ships."; return 0; }

                                
                                
                                • 0
                                  @ 2025-12-9 15:33:39
                                  using namespace std;
                                  int fx[5]={0,-1,1,0,0},fy[5]={0,0,0,-1,1},n,m,tx,ty,s,maxn=INT_MIN;
                                  bool f[1100][1100];
                                  char a[1100][1100];
                                  void sy(int x,int y)
                                  {
                                  	for(int i=1;i<=4;i++)
                                      {
                                  		tx=x+fx[i];
                                  		ty=y+fy[i];
                                  		if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&f[tx][ty]==0&&a[tx][ty]=='*')
                                          {
                                  			s++;
                                  			f[tx][ty]=1;
                                  			sy(tx,ty);
                                  		}
                                  	}
                                  }
                                  int main()
                                  {
                                  	cin>>m>>n;
                                  	for(int i=1;i<=n;i++)
                                  		for(int j=1;j<=m;j++) cin>>a[i][j];
                                  	for(int i=1;i<=n;i++)
                                  		for(int j=1;j<=m;j++)
                                  			if(a[i][j]=='*'&&f[i][j]==0)
                                              {
                                  				f[i][j]=1;
                                  				s=1;
                                  				sy(i,j);
                                  				maxn=max(maxn,s);
                                  			}
                                  	cout<<maxn;
                                  	return 0;
                                  }
                                  
                                  • 0
                                    @ 2025-11-17 17:44:02

                                    谁能告诉我,为什么我提交了3次,显示我没交!

                                    • 0
                                      @ 2025-11-14 16:39:35
                                      using namespace std;
                                      long long n,a[1000][1000],f[1000][1000];
                                      int sy(int x,int y)
                                      {
                                          if(x==n) f[x][y]=a[x][y];
                                      	if(x==n+1) return 0;
                                      	if(f[x][y]==0) f[x][y]=max(sy(x+1,y),sy(x+1,y+1))+a[x][y];
                                          return f[x][y];
                                      }
                                      int main()
                                      {
                                          cin>>n;
                                      	for(int i=1;i<=n;i++)
                                      	    for(int j=1;j<=i;j++) cin>>a[i][j];
                                      	cout<<sy(1,1);
                                      	return 0;
                                      }
                                      
                                      • 0
                                        @ 2025-11-14 15:26:12
                                        using namespace std;
                                        int v[200],w[200],n,V;
                                        int sy(int s,int k)
                                        {
                                            if(s<=0||k==0) return 0;
                                            if(s>=v[k])return max(sy(s,k-1),sy(s-v[k],k-1)+w[k]);
                                            else return sy(s,k-1);
                                        }
                                        int main()
                                        {
                                        	cin>>n>>V;
                                        	for(int i=1;i<=n;i++) cin>>v[i]>>w[i];
                                            cout<<sy(V,n);
                                        }
                                        
                                        • 1

                                        信息

                                        ID
                                        103
                                        时间
                                        1000ms
                                        内存
                                        256MiB
                                        难度
                                        6
                                        标签
                                        递交数
                                        47
                                        已通过
                                        15
                                        上传者