当前位置:网站首页>Write some DP
Write some DP
2022-07-29 07:33:00 【A little Yu】
Flowers 【noip2012】 Popularization group
Title Description
Xiaoming's florist is newly opened , To attract customers , He wants to put a row of flowers in front of the flower shop , common m basin . By investigating customer preferences , Xiao Ming listed the customers' favorite n grow flowers , from 1 To n label . To show more flowers at the door , Rule No i You can't plant more than ai basin , When arranging flowers, put the same kind of flowers together , And different kinds of flowers need to be arranged in order from small to large .
Trial programming calculation , How many different flower arrangements are there .
Input format
The first line contains two positive integers n and m, Separated by a space .
The second line has n It's an integer , Every two integers are separated by a space , Sequential representation a1,⋯,an.
Output format
An integer , Indicates how many options there are . Be careful : Because the number of schemes may be many , Please output the number of scheme pairs 10^6+7 Results of die taking .
I/o sample
Input #1 Copy
2 4 3 2Output #1 Copy
2explain / Tips
【 Data range 】
about 20\%20% data , Yes 0<n \le 8,0<m \le 8,0 \le a_i \le 80<n≤8,0<m≤8,0≤ai≤8.
about 50\%50% data , Yes 0<n \le 20,0<m \le 20,0 \le a_i \le 200<n≤20,0<m≤20,0≤ai≤20.
about 100\%100% data , Yes 0<n \le 100,0<m \le 100,0 \le a_i \le 1000<n≤100,0<m≤100,0≤ai≤100.
NOIP 2012 Popularization group Third question
1. Search for
#include<bits/stdc++.h>
using namespace std;
const int maxn=105, mod = 1000007;
int n, m, a[maxn];
int dfs(int x,int k)
{
if(k > m) return 0;
if(k == m) return 1;
if(x == n+1) return 0;
int ans = 0;
for(int i=0; i<=a[x]; i++) ans = (ans + dfs(x+1, k+i))%mod;
return ans;
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>a[i];
cout<<dfs(1,0)<<endl;
return 0;
}2. Memory search
#include<bits/stdc++.h>
using namespace std;
const int maxn=105, mod = 1000007;
int n, m, a[maxn], rmb[maxn][maxn];
int dfs(int x,int k)
{
if(k > m) return 0;
if(k == m) return 1;
if(x == n+1) return 0;
if(rmb[x][k]) return rmb[x][k]; // Search and return
int ans = 0;
for(int i=0; i<=a[x]; i++) ans = (ans + dfs(x+1, k+i))%mod;
rmb[x][k] = ans; // Record the results of the current state
return ans;
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>a[i];
cout<<dfs(1,0)<<endl;
return 0;
}3. Two dimensional dynamic programming
#include<bits/stdc++.h>
using namespace std;
const int maxn=105, mod = 1000007;
int n, m, a[maxn], f[maxn][maxn];
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>a[i];
f[0][0] = 1;
for(int i=1; i<=n; i++)
for(int j=0; j<=m; j++)
for(int k=0; k<=min(j, a[i]); k++)
f[i][j] = (f[i][j] + f[i-1][j-k])%mod;
cout<<f[n][m]<<endl;
return 0;
}4. One dimensional dynamic programming
#include<bits/stdc++.h>
using namespace std;
const int maxn=105, mod = 1000007;
int n, m, a[maxn], f[maxn];
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++) cin>>a[i];
f[0] = 1;
for(int i=1; i<=n; i++)
for(int j=m; j>=0; j--) // Be careful , yes 01 knapsack
for(int k=1; k<=min(a[i], j); k++)
f[j] = (f[j] + f[j-k])%mod;
cout<<f[m]<<endl;
return 0;
}边栏推荐
- 【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
- 关于大龄读博的几点回答?
- 电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
- Prometheus and grafana
- 监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
- Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
- logback日志级别简介说明
- 【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
- [100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common
- Meizhi optoelectronics' IPO was terminated: annual revenue of 926million he Xiangjian was the actual controller
猜你喜欢

stm32 操作W25Q256 W25Q16 spi flash

cs61abc分享会(六)程序的输入输出详解 - 标准输入输出,文件,设备,EOF,命令行参数

如何与斯堪尼亚SCANIA建立EDI连接?

How can electronic component trading enterprises solve warehouse management problems with ERP system?

Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)

2-统一返回类DTO对象

Meizhi optoelectronics' IPO was terminated: annual revenue of 926million he Xiangjian was the actual controller

Job 7.28 file IO and standard IO

Using C language to skillfully realize the chess game -- Sanzi chess

3-global exception handling
随机推荐
QT连接两个qslite数据库报错QSqlQuery::exec: database not open
Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
零数科技深度参与信通院隐私计算金融场景标准制定
The beauty of do end usage
Halcon installation and testing in vs2017, DLL configuration in vs2017
Starting process of raspberry pie
halcon的安装以及在vs2017中测试,vs2017中dll的配置
美智光电IPO被终止:年营收9.26亿 何享健为实控人
写点dp
cdc source能读完MySqlSnapshotSplit 就退出嘛
【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
09 bloom filter
Pat class a 1146 topology sequence
String类
Dilworth 定理
利用C语言巧妙实现棋类游戏——三子棋
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
【WPF】通过动态/静态资源实现语言切换
MySQL如何把行转换为列?