http://oj.ecustacm.cn/problem.php?id=1391
#include <iostream> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cstring> //#include<unordered_map> typedef long long LL; using namespace std; int main(){ for(int i=1;i<=10;i++){ int j=(200-21*i)/5; if(5*j+21*i==200){ int ans=11*i+j; cout<<ans<<endl; break; } } return 0; } // freopen("testdata.in", "r", stdin);
http://oj.ecustacm.cn/problem.php?id=1392
#include <iostream> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cstring> using namespace std; long long ans; int check(int i,int j){ return i>>j &1; } int main(){ // for(int i=0;i<(1<<30);i++){//二进制枚举1为开灯0为不开 // int flag=1; // for(int j=1;j<30;j++){ // if(check(i,j)&&check(i,j-1)){//如果相邻的两位都是1就不行 // flag=0; // break; // } // } // ans+=flag; // } ans=2178309; cout<<ans; return 0; }
http://oj.ecustacm.cn/problem.php?id=1393
#include <iostream> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cstring> using namespace std; int res; typedef struct{ int temp; int time; }QQ; queue<QQ> q; int n,k; int vis[100005]; int cnt; int main(){ QQ e1,e2; cin>>n>>k; e1.time=0; e1.temp=0; q.push(e1); while(!q.empty()){ e2=q.front(); q.pop(); int a=(e2.time+k)%n; int b=(e2.time+1)%n; if(!vis[a]){ vis[a]=e2.temp+1; e1.temp=e2.temp+1; e1.time=a; q.push(e1); } if(!vis[b]){ vis[b]=e2.temp+1; e1.temp=e2.temp+1; e1.time=b; q.push(e1); } } for(int i=1;i<n;i++){ res=max(res,vis[i]); } cout<<res<<endl; return 0; }
DP加前缀和。
很复杂
http://oj.ecustacm.cn/problem.php?id=1394
#include <iostream> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cstring> //#include<unordered_map> typedef long long LL; using namespace std; const int N=110,mod=1e9+7; int n,m; LL s[N][N]; int c[N][N]; LL f[N][N][N]; LL get_sum(int x1,int y1,int x2,int y2){ return (s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1])%mod; } void get_prefix_sum(int i){ for(int j=1;j<=m;j++){ for(int k=j;k<=m;k++){ s[j][k]=(s[j-1][k]+s[j][k-1]-s[j-1][k-1]+f[i][j][k])%mod; } } } int main(){ cin>>n>>m; char str[N]; for(int i=n;i;i--){ cin>>str+1; for(int j=1;j<=m;j++){ c[i][j]=c[i][j-1]+(str[j]=='X'); } } //初始DP数组 f[0][1][m]=1; get_prefix_sum(0); int res=1; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ for(int k=j;k<=m;k++){ if(c[i][k]-c[i][j-1]==0){ LL &x=f[i][j][k]; x=(x+get_sum(1,k,j,m))%mod; res=(res+x)%mod; } } } get_prefix_sum(i); } cout<<(res+mod)%mod<<endl; return 0; } // freopen("testdata.in", "r", stdin);